美文网首页
iOS 手势的的禁止

iOS 手势的的禁止

作者: 骑着老鼠虐大象 | 来源:发表于2016-09-11 14:00 被阅读84次

    上篇文章讲到给WebView添加手势和webView不能添加手势的原理,于是脑洞大开,禁止手势添加,应用场景:高度自定义控件,并且禁止手势添加。

    方法如下:

    方法一:遍历controller  包含的所有view 的所有手势,设置手势enabled属性NO;

    方法二:遍历controller  包含的所有view 的所有手势,设置手势cancelsTouchesInView属性YES;

    这些方法只能在手势添加完成后实现,那么最好写在viewDidLoad方法里,缺点是重写这个方法

    还有一个思路可以解决这件事,利用KVO监听手势的添加,本来想监听手势的数目,可是

    [<__NSArrayI 0x1245c7f40> addObserver:forKeyPath:options:context:] is not supported. Key path: count'

    Special Considerations

    NSArrayobjects are not observable, so this method raises an exception when invoked on anNSArrayobject. Instead of observing an array, observe the to-many relationship for which the array is the collection of related objects.

    数组不支持KVO

    相关文章

      网友评论

          本文标题:iOS 手势的的禁止

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