Ios 完成块isn';在旋转期间更新UIPageViewController时调用

Ios 完成块isn';在旋转期间更新UIPageViewController时调用,ios,objective-c,uipageviewcontroller,screen-rotation,Ios,Objective C,Uipageviewcontroller,Screen Rotation,我正在尝试在旋转期间更新UIPageViewController中的当前页面,如下所示: - (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration { NSArray *controllers = @[someViewController]; UIPageViewControllerNavigat

我正在尝试在旋转期间更新
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.
    }];
}
但是,出于某种原因,在这种情况下,永远不会调用completion块,而当我从其他地方调用具有相同参数的相同方法时,它会按预期进行调用

有人能证实这个奇怪的行为吗?这是
UIPageViewController
中的一个bug还是我的误用

更新

我发现,如果我将参数
animated
更改为
NO
,则会按预期调用完成块!因此,在我看来,这更像是
UIPageViewController

的一个bug,尝试一下:

- (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) {
        ///
    }];
}

发现了相同的问题:如果
someViewController
是当前可见的控制器或
pageController.viewControllers?。首先将
animated
标志设置为true,然后调用
setViewControllers
,而不调用完成处理程序。最简单的方法是调用
setViewControllers
,将
animated
标志设置为false。不会显示动画,但仍将调用完成处理程序。但在大多数情况下,需要显示动画。因此,这里唯一可能的解决方法是检查要设置的viewController是否不是可见的。如果是,则应调用
setViewControllers
,并将
animated
标志设置为false:

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

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

希望对你有帮助

这里的区别是什么?因为您在委托方法中执行此操作。如果你这样做。它将从saparat方法调用。如果这也不起作用,请使用延迟为0.01的PerformSelector进行尝试。将代码移动到新方法并仅调用该方法并不意味着它将在另一个线程中执行。尽管如此,我只是想知道这是
UIPageViewController
的一个bug还是对我的滥用。你试过了吗?好的,照你想的那样做在我的例子中,当我试图设置self.pageViewController.viewControllers.firstObject中已有的控制器时,我遇到了问题