ExclusiveTouch的设置与作用

作者: MindTheGap | 来源:发表于2015-07-28 09:51 被阅读12428次

    ExclusiveTouch的作用是:可以达到同一界面上多个控件接受事件时的排他性,从而避免bug。也就是说避免在一个界面上同时点击多个UIButton导致同时响应多个方法

    - (void)setExclusiveTouchForButtons:(UIView *)myView {

              for (UIView * v in [myView subviews]) {

                    if([v isKindOfClass:[UIButton class]]) {

                          [((UIButton *)v) setExclusiveTouch:YES];

                     }else if ([v isKindOfClass:[UIView class]]) {

                           [self setExclusiveTouchForButtons:v];

                      }

               }

     }

    看见有人用这个来控制UIButton 的ExclusiveTouch属性,这样需要在每个控制器都要设置。可用一句话来代替这样的设置,在AppDelegate启动应用时添加 [[UIButton appearance] setExclusiveTouch:YES];


    注意:下面有个同学提醒-->这个方法仅支持iOS 8.0+系统。

    相关文章

      网友评论

      • 18b7e4b39401:当UIView的exclusiveTouch属性设置为YES时,UIView可以独占当前窗口的touch事件。
        在手指离开屏幕之前,其他视图都无法触发touch事件。
      • drmi:楼主,在appdelegate中的didFinishLaunchingWithOptions方法中加上那段代码吗, 结果:无效
        drmi:@MindTheGap 最终,换上 [[UIView appearance] setExclusiveTouch:YES]; 这句可以,btn就是不行,不晓得为什么,既然同事点击,还是全局设置的好
        MindTheGap:@drmi 对这两个button单独设置一下这个属性就好了。😆
        drmi:2个按钮都是跳转,同时按下,还是连续跳转2次
      • 45015e150d40:[[UIButton appearance] setExclusiveTouch:YES];仅支持iOS 8.0+系统
        343cea0f7107:@MindTheGap 为什么是仅支持iOS8.0呢?
        MindTheGap:@Holaween 对的对的!~ :clap:

      本文标题:ExclusiveTouch的设置与作用

      本文链接:https://www.haomeiwen.com/subject/mnpmqttx.html