iOS 手势的的禁止

2016-09-11  本文已影响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

上一篇下一篇

猜你喜欢

热点阅读