interactivePopGestureRecognizer的问题(导航控制器向后滑动)

时间:2015-04-17 11:44:11

标签: ios xcode

我的第一个问题,请温柔......

如果我使用UIPageViewControllerTransitionStylePageCurl,则从页面控制器向后滑动可以正常工作,但不能使用UIPageViewControllerTransitionStyleScroll。我不明白为什么它反对后者。有什么想法吗?

过渡风格取决于演示模式:

if (inPageCurlMode) {
    // this swipes back fine
    self.pageViewController = [[UIPageViewController alloc]
    initWithTransitionStyle:
       UIPageViewControllerTransitionStylePageCurl  
    navigationOrientation:
       UIPageViewControllerNavigationOrientationHorizontal
    options:nil];
    }
else {
    // this won't swipe back
    self.pageViewController = [[UIPageViewController alloc]
    initWithTransitionStyle:
       UIPageViewControllerTransitionStyleScroll
    navigationOrientation:
       UIPageViewControllerNavigationOrientationHorizontal
    options:nil];        
    }  

1 个答案:

答案 0 :(得分:0)

以下内容在UIPageViewController子类中为我工作:

    override func viewDidAppear(_ animated: Bool) {
    super.viewDidAppear(animated)

    for subview in self.view.subviews {

        if let scrollview = subview as? UIScrollView{

            if let gestures = scrollview.gestureRecognizers{

                for gesture in gestures {
                    gesture.require(toFail: self.navigationController!.interactivePopGestureRecognizer!)
                }
            }
        }
    }
}

请确保navigationController可用,这就是我将其放入 viewDidAppear()

的原因