iOS中解决各种手势冲突问题


UIScorllView的滑动手势 与push方法自带的 或者自己加的侧边放回上一个页面手势

// 自定义UIScrollView, 在里面复制下面代码..

  kWidth为屏幕宽度~~~~

- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer
{
    // 判断当前的移动方向 velocity > 0 向右滑 反之...
    CGPoint velocity = [(UIPanGestureRecognizer *)gestureRecognizer velocityInView:self];
    // 获取手势在屏幕上的初始点
    CGPoint location = [gestureRecognizer locationInView:self];
//    NSLog(@"velocity.x:%f----location.x:%d",velocity.x,(int)location.x % (int)kWidth);
    // 判断一下
    if (velocity.x > 0 && (int)location.x % (int)kWidth < 60) {
        return NO;
    }
    return YES;
}

各种有点击方法的空间 例如Button 与手势中轻拍等手势的冲突 只需写一个通知判断一下即可

<span style="font-size:24px;">   </span><span style="font-size:14px;"> NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
    [center addObserver:self selector:@selector(closeNotification) name:@"closeUserInteractionEnabled" object:nil];
    [center addObserver:self selector:@selector(openNotification) name:@"openUserInteractionEnabled" object:nil];

// 实现通知
- (void)closeNotification
{
    for (int i = 0; i < 4; i++) {
        UIButton *button = (UIButton *)[View viewWithTag:100 + i];
        button.userInteractionEnabled = NO;
        }
}

- (void)openNotification
{
    for (int i = 0; i < 4; i++) {
        UIButton *button = (UIButton *)[_radioMainView viewWithTag:100 + i];
        button.userInteractionEnabled = YES;
    }
}</span>
<span style="font-size:14px;">
</span>
<span style="font-size:14px;">// 自己应该能判断一下何时需要开启或者关闭交互吧 ....
[[NSNotificationCenter defaultCenter] postNotificationName:@"closeUserInteractionEnabled" object:self userInfo:nil];
[[NSNotificationCenter defaultCenter] postNotificationName:@"openUserInteractionEnabled" object:self userInfo:nil];</span><span style="font-size:24px;">
</span>



更多手势冲突问题请加Q 291975388 ~~

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值