I have a UIScrollView where I added a subview. The scrollview scrolls fine vertically and that is all it should do. I would now like to recognize left/right swipes in the subview with the help of a UISwipeGestureRecognizer. I know it is possible, but I have not come across a solution and several tries have been unsuccessful.
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
Try these:
Set the delegate of your
UIGestureRecognizer
andImplement
shouldRecognizeSimultaneouslyWithGestureRecognizer
:-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer{ return YES; }
Implement
shouldReceiveTouch
:- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch { return YES; }
Hope this helps
回答2:
I was able to accomplish something related (adding a two-finger swipe gesture recognizer directly on the scroll view) with the new iOS 7 UIGestureRecognizerDelegate method:
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer
shouldBeRequiredToFailByGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
{
return otherGestureRecognizer == scrollView.panGestureRecognizer;
}
However, the results were not perfect - the delay waiting for the swipe gesture recognizer to fail first causes a lag in the scrollview's pan gesture recognizer getting its touches, so normal scrolling is noticeably delayed when you start to scroll.