UIScrollView、PanGestureRecognizer 和 iOs 4
我有一个可滚动视图,我需要手势识别器,该手势识别器将在不滚动主视图的情况下触发。
我使用过这段代码:
UISwipeGestureRecognizer *upRecognizer =
[[UISwipeGestureRecognizer alloc] initWithTarget:self
action:@selector(upSwipeHandle:)];
upRecognizer.direction = UISwipeGestureRecognizerDirectionUp;
[upRecognizer setNumberOfTouchesRequired:2];
[controller.view addGestureRecognizer:upRecognizer];
[[controller.scrollView panGestureRecognizer]
requireGestureRecognizerToFail:upRecognizer];
但它似乎只在 iOS 5 中工作。我如何在 iOS 4 中使用相同的识别器?
I have a scrollable view and I need the gesture recognizer that will fire without scrolling of main view.
I've used this code:
UISwipeGestureRecognizer *upRecognizer =
[[UISwipeGestureRecognizer alloc] initWithTarget:self
action:@selector(upSwipeHandle:)];
upRecognizer.direction = UISwipeGestureRecognizerDirectionUp;
[upRecognizer setNumberOfTouchesRequired:2];
[controller.view addGestureRecognizer:upRecognizer];
[[controller.scrollView panGestureRecognizer]
requireGestureRecognizerToFail:upRecognizer];
But it seems to work only in iOS 5. How can I use the same recognizer in iOS 4?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我通过使用 UIGestureRecognizer 委托方法解决了我的问题。
只需添加
这个方法:
I Solve my problem by using UIGestureRecognizer delegate method.
just add
and this method:
我遇到了同样的问题。我在 4.3 模拟器中运行了类似的代码,但该代码失败了,因为 scrollView.panGestureRecognizer 仅在 iOS 5.0+ 中可用。
我通过向 UIScrollView 添加一个类别来解决这个问题。
I ran into the same issue. I ran similar code in the 4.3 simulator and that code failed because scrollView.panGestureRecognizer is only available in iOS 5.0+.
I solved it by adding a category to UIScrollView.