ios的手势互斥,工程通过手势的代理和手势的一个方法解决,代理的主要作用可以用于手势的互斥和共存 下面几个重要的代理方法:
手势和touch事件会优先响应手势,默认手势识别后touch就会调用cancel方法取消
///手势已经识别出来了,但是手势是否响应由它决定 - (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer { return YES; }
///本手势是否和other另外一个手势共存;你只要有一个手势,这个代理方法返回了YES,那么就是共存 - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer { return YES; }
///otherGestureRecognizer它要识别,需要gestureRecognizer被响应失败 //- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldBeRequiredToFailByGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer { // // return YES; }
///手势是否接受touch事件 - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch { return YES; }
///gestureRecognizer 需要otherGestureRecognizer响应失败 //- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRequireFailureOfGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer { // // return YES; // //}
手势还有一个方法- (void)requireGestureRecognizerToFail:(UIGestureRecognizer *)otherGestureRecognizer; (本手势的响应需要otherGestureRecognizer响应失败)
多个手势,手势的touch方法是没有顺序的,不要去纠结句号句号,手势和touch事件一起会优先响应手势。