iOS 8 UIPageViewController 在转换后应用约束 [英] iOS 8 UIPageViewController Applying Constraints After Transitions

查看:22
本文介绍了iOS 8 UIPageViewController 在转换后应用约束的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用有一个多窗格教程风格的视图,用户可以通过滑动来了解应用.这与本教程中描述的非常相似.在 iOS 7 和 8 上都实现了它,我正在比较它们的工作方式,并找出后者的问题——我在这里运行的是 Xcode 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 pt 空白区域.过渡完成后,它会进入正确的布局.

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.

你可以这样做:

记得取消选中约束到边距"

Remember to uncheck "Constrain to margins"

这篇关于iOS 8 UIPageViewController 在转换后应用约束的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆