在旋转期间更新UIPageViewController时不会调用完成块

时间:2013-10-09 09:26:07

标签: ios objective-c uipageviewcontroller screen-rotation

我正在尝试在轮播期间更新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中的错误或只是误用了我?

更新

我发现如果我将参数animated更改为NO,将按预期调用完成块!所以,对我而言,这似乎是UIPageViewController的错误。

2 个答案:

答案 0 :(得分:4)

遇到同样的问题,发现以下内容:如果someViewController是当前可见控制器或pageController.viewControllers?.firstanimated标志设置为true,则调用setViewControllers不调用完成处理程序。最简单的方法是在setViewControllers标志设置为false的情况下调用animated。不会显示任何动画,但无论如何都会调用完成处理程序。但在大多数情况下,您需要显示动画。因此,这里唯一可行的解​​决方法是检查要设置的viewController是否不可见。如果是,则应将setViewControllers调用animated并将let completionBlock: (Bool) -> Void let isAnimated = (newController != pageController.viewControllers?.first) pageController.setViewControllers([newController], direction: .forward, animated: isAnimated, completion: completionBlock) 标志设置为false:

package javaapplication1;
import javassist.ClassPool;
import javassist.CtClass;

public class JavaApplication1 {
    public static void main(String[] args) throws Exception {
        ClassPool pool = ClassPool.getDefault();  
        CtClass cc = pool.makeClass("Point2");
    }
}

希望能帮到你!

答案 1 :(得分:-1)

尝试为:

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