似乎在切换到Xcode 6和新的iOS 8 SDK后,我的UIPageViewController被破坏了。我第一次将项目加载到UIPageViewController并显示它们时似乎工作正常但是当我以编程方式转换到下一页时,页面视图控制器的子视图由于某种原因改变了大小。以下是我用来设置页面视图控制器和转换的代码:
if (!self.coverViewController) {
self.coverViewController = [[UIPageViewController alloc]
initWithTransitionStyle:UIPageViewControllerTransitionStyleScroll
navigationOrientation:UIPageViewControllerNavigationOrientationHorizontal
options:nil];
self.coverViewController.edgesForExtendedLayout = UIRectEdgeAll;
self.coverViewController.extendedLayoutIncludesOpaqueBars = YES;
self.coverViewController.automaticallyAdjustsScrollViewInsets = NO;
}
NSArray* startingViewController = @[[self updatePageViewController:arc4random() % self.dataSource.numberOfItems]];
[self.coverViewController setViewControllers:startingViewController direction:UIPageViewControllerNavigationDirectionForward animated:NO completion:nil];
[self.coverViewController.view setClipsToBounds:YES];
[self updateFocusAndTrainingLabel];
[self.coverViewController.view setTranslatesAutoresizingMaskIntoConstraints:NO];
[self addChildViewController:self.coverViewController];
[self.coverViewController didMoveToParentViewController:self];
[self.view addSubview:self.coverViewController.view];
NSDictionary* views = @{@"cover":self.coverViewController.view};
[self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"|[cover]|" options:0 metrics:nil views:views]];
[self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[cover]|" options:0 metrics:nil views:views]];
[self.view layoutIfNeeded];
-(IBAction)pageForward:(id)sender {
if (self.dataSource.numberOfItems > 1) {
[self changePage:UIPageViewControllerNavigationDirectionForward];
}
}
- (void)changePage:(UIPageViewControllerNavigationDirection)direction {
int pageIndex = [self.coverViewController.viewControllers objectAtIndex:0]).pageIndex;
if (direction == UIPageViewControllerNavigationDirectionForward) {
pageIndex++;
}
else if (direction == UIPageViewControllerNavigationDirectionReverse) {
pageIndex = pageIndex - 1;
}
if (pageIndex < 0) {
pageIndex = self.coverFlowPages.count - 1;
} else if (pageIndex >= self.coverFlowPages.count) {
pageIndex = 0;
}
UIViewController *viewController = [self updatePageViewController:pageIndex];
if (viewController == nil) {
return;
}
__weak typeof(self)weakSelf = self;
self.nextItemButton.userInteractionEnabled = NO;
self.previousItemButton.userInteractionEnabled = NO;
[self.coverViewController setViewControllers:@[viewController]
direction:direction
animated:NO
completion:^(BOOL finished) {
if (finished) {
weakSelf.nextItemButton.userInteractionEnabled = YES;
weakSelf.previousItemButton.userInteractionEnabled = YES;
[weakSelf updateLabels];
}
}];
}
奇怪的是,当你水平滑动以更改页面时,只有在使用pageForward时它才能正常工作:视图控制器是否会改变高度。 UIPageViewControllers高度保持不变,但我可以看到_QueueScrollView高度在转换后发生了变化。
任何帮助都会很棒!我已经看了一会儿这个问题并且无法解决问题。不确定它是iOS 8的bug还是什么?在iOS 7上完美运行