iOS的8 UIPageViewController应用约束后转换 [英] iOS 8 UIPageViewController Applying Constraints After Transitions
问题描述
我的应用程序有一个多窗格的教程式的观点,即用户通过刷卡来了解应用程序。实现此方法非常多在本教程中描述。已经实现了它为iOS的7和8,我比较他们的工作,并与后者发现问题 - 我跑X code 6 GM此处
My app has a multi-pane tutorial-style view that users swipe through to learn about the app. This is implemented very much as described in this tutorial. Having implemented it for both iOS 7 and 8, I'm comparing how they work, and finding issues with the latter — I'm running Xcode 6 GM here.
看来,UIPageViewController被渲染视图的转换完成后。我推翻委托方法,看看发生了什么事情:
It seems that the UIPageViewController is rendering the views after the transition is complete. I overrode the delegate methods to see what was going on:
- (void)pageViewController:(UIPageViewController *)pageViewController willTransitionToViewControllers:(NSArray *)pendingViewControllers
{
NSLog(@"Frame size before: %@", NSStringFromCGRect([(UIViewController*)pendingViewControllers[0] view].frame));
}
- (void)pageViewController:(UIPageViewController *)pageViewController didFinishAnimating:(BOOL)finished previousViewControllers:(NSArray *)previousViewControllers transitionCompleted:(BOOL)completed
{
NSLog(@"Frame size after: %@", NSStringFromCGRect([(UIViewController*)previousViewControllers[0] view].frame));
}
这是一个示例输出:
Frame size before: {{0, 0}, {600, 600}}
Frame size after: {{0, 0}, {320, 568}}
这体现,像这样:向左滑动,在未来的看法拉,并注意在新视图的底部一个32磅的空白。一旦过渡完成后,抽搐成适当的布局。
This manifests like so: swipe to the left to pull in the next view, and note a 32-pt white space at the bottom of the new view. Once the transition is complete, it jerks into its proper layout.
这是一个错误的iOS 8,也许?我已与猜测在这一点上。
Is this a bug in iOS 8, perhaps? I'm all out of guesses at this point.
推荐答案
我想通了,你需要立足于视图,而不是你的视图控制器的布局导向的约束。这将确保您的视图控制器尊重你之前在PageViewController过渡设置的限制。
I figured out you need to base your constraints on the view and not the layout guide of your view controller. This will ensure your view controller respects the constraints you set prior to the transition in a PageViewController.
你可以做到这一点像这样:
you can do this like so:
记住要取消约束边距
这篇关于iOS的8 UIPageViewController应用约束后转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!