UIPageViewController 在 iOS 6 中不返回手势识别器

UIPageViewController returns no Gesture Recognizers in iOS 6(UIPageViewController 在 iOS 6 中不返回手势识别器)

本文介绍了UIPageViewController 在 iOS 6 中不返回手势识别器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试禁用 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.

有什么办法可以解决这个问题吗?我认为我没有做错任何事,因为 curl 过渡效果很好.

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开启时,会阻止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.

我知道这是 hack,但是面对 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 中不返回手势识别器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:UIPageViewController 在 iOS 6 中不返回手势识别器

基础教程推荐