6

我正在尝试UIPageViewController在轮换期间更新当前页面,如下所示:

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
    NSArray *controllers = @[someViewController];
    UIPageViewControllerNavigationDirection direction = UIPageViewControllerNavigationDirectionForward;

    [self.pageController setViewControllers:controllers direction:direction animated:YES completion:^(BOOL finished) {
        /// This completion block isn't called ever in this case.
    }];
}

但是,由于某种原因,在这种情况下永远不会调用完成块,而当我从其他地方调用具有相同参数的相同方法时,它会按预期调用。

任何人都可以确认这种奇怪的行为,如果它是我的错误UIPageViewController或只是滥用我?

更新

我发现如果我将参数更改animatedNO完成块将按预期调用!所以,在我看来,这是一个错误UIPageViewController

4

2 回答 2

7

遇到同样的问题,发现了以下情况:如果someViewController是当前可见控制器或者pageController.viewControllers?.first并且animated标志设置为真,那么setViewControllers在不调用完成处理程序的情况下被调用。最简单的方法是将标志设置为 false 进行setViewControllers调用animated。不会显示任何动画,但无论如何都会调用完成处理程序。但在大多数情况下,您需要显示动画。因此,这里唯一可能的解决方法是检查要设置的 viewController 是否不是可见的。如果是,您应该调用设置为 false setViewControllers的标志:animated

let completionBlock: (Bool) -> Void
let isAnimated = (newController != pageController.viewControllers?.first)

pageController.setViewControllers([newController],
                                  direction: .forward,
                                  animated: isAnimated, 
                                  completion: completionBlock)

希望对你有帮助!

于 2017-04-19T18:35:49.877 回答
-2

试试看:

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
    [self newMethod];
  // or  [self performSelector:@selector(newMethod) withObject:self afterDelay:0.01];
}

- (void)newMethod{
    NSArray *controllers = @[someViewController];
    UIPageViewControllerNavigationDirection direction = UIPageViewControllerNavigationDirectionForward;

    [self.pageController setViewControllers:controllers direction:direction animated:YES          completion:^(BOOL finished) {
        ///
    }];
}
于 2013-10-09T09:58:27.257 回答