问题描述
我正在尝试为UIPageViewController禁用平移手势识别器。
I am trying to disable the pan gesture recognizer for a UIPageViewController.
在iOS 5上,我可以遍历它们并禁用它们。
On iOS 5 I can loop through them and disable them.
for (UIGestureRecognizer* recognizer in self.pageViewController.gestureRecognizers) {
if ([recognizer isKindOfClass:[UIPanGestureRecognizer class]]) {
recognizer.enabled = NO;
}
}
在使用UIPageViewControllerTransitionStyleScroll的iOS 6上,没有返回手势识别器通过页面视图控制器。
On iOS 6 using UIPageViewControllerTransitionStyleScroll there are no gesture recognizers returned by the Page View Controller.
这可以归结为:
当UIPageViewController的过渡样式设置为滚动时,self.pageViewController.gestureRecognizers = 0,因此我无法访问手势识别器。
self.pageViewController.gestureRecognizers = 0 when UIPageViewController's transition style is set to scroll so I can't access the gesture recognizers.
是有什么方法可以解决这个问题吗?由于卷曲过渡工作正常,我认为我没有做错任何事。
Is there any way I can get around this? I don't think I am doing anything wrong since the curl transition works fine.
推荐答案
有一个。所以,我敢打赌,直到Apple修复它才有机会解决这个问题。
There is a bug filed in radar for this behavior. So, I bet that until Apple fixes it there will be no chance to solve this.
我想到的一个解决方法是在你的 UIPageViewController 并添加一个 UIPanGestureRecognizer
来截取这种手势而不是进一步前进。你可以在需要禁用手势时启用此视图/识别器。
One workaround that comes to my mind is laying a transparent subview on top of your UIPageViewController
and add to it a UIPanGestureRecognizer
to intercept that kind of gesture and not forward further. You could enable this view/recognizer when disabling the gesture is required.
我尝试使用Pan和Tap手势识别器的组合,它可以工作。
I tried it with a combination of Pan and Tap gesture recognizers and it works.
这是我的测试代码:
- (void)viewDidLoad {
[super viewDidLoad];
UIPanGestureRecognizer* g1 = [[[UIPanGestureRecognizer alloc] initWithTarget:self
action:@selector(g1Pan:)] autorelease];
[self.view addGestureRecognizer:g1];
UITapGestureRecognizer* s1 = [[[UITapGestureRecognizer alloc] initWithTarget:self
action:@selector(g1Tap:)] autorelease];
[self.view addGestureRecognizer:s1];
UIView* anotherView = [[[UIView alloc]initWithFrame:self.view.bounds] autorelease];
[self.view addSubview:anotherView];
UIPanGestureRecognizer* g2 = [[[UIPanGestureRecognizer alloc] initWithTarget:self
action:@selector(g2Pan:)] autorelease];
[anotherView addGestureRecognizer:g2];
}
当 g2 $ c时$ c>已启用,它将阻止
g1
被识别。另一方面,它不会阻止s1被识别。
When g2
is enabled, it will prevent g1
from being recognized. On the other hand, it will not prevent s1 from being recognized.
我知道这是黑客,但面对中的一个看似错误UIPageViewController
(至少,实际行为与参考状态明显不同),我看不出更好的解决方案。
I understand this is hack, but in the face of a seeming bug in UIPageViewController
(at least, actual behavior is blatantly different from what the reference states), I cannot see any better solution.
这篇关于UIPageViewController在iOS 6中不返回Gesture Recognizers的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!