iOS 8 / XCode 6 autolayout constraints applied after view appears(视图出现后应用的 iOS 8/XCode 6 自动布局约束)
问题描述
I have a project that was working just fine with XCode 5 and iOS 7, but when I recently downloaded XCode 6, I noticed some weird behavior with autolayout.
I have a storyboard with a view that just has a UIImageView and two UILabels. This view gets loaded using a UiPageViewController. The UIImageView is centered horizontally and vertically in the view and there are constraints specifying the distance of the two labels from the image view. When there is a case when the storyboard and autolayout values conflict (for example, in the storyboard, one label is 20 pixels above the image view but the autolayout says it should be 40 pixels above), it used to be that the autolayout value was successfully applied before the view loaded. Thus, when the view gets shown for the first time, everything is in the right place.
Now with iOS 8 / XCode 6, I'm seeing that the view loads and then things jump to their final autolayout position. This jump is noticeable to the end user both in the simulator and on a real device, and it's really annoying. Is there a way to go back to the old behavior? As far as I'm aware, no code has changed to cause this issue.
Where is your code that is making changes to your constraints?
If you're keeping it in viewWillAppear: you will have that problem. I found that viewDidLayoutSubviews works well for iOS8 but not always for iOS7 backwards.
Eventually, if you cant use viewDidLayoutSubviews, what I'd suggest is hide the container view in viewDidLoad and unhide it in viewWillAppear, only after the constraints have been applied. It gets you a small extra delay when loading the screen but the constraints change gets transparent to the user.
这篇关于视图出现后应用的 iOS 8/XCode 6 自动布局约束的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:视图出现后应用的 iOS 8/XCode 6 自动布局约束
基础教程推荐
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01
- android 应用程序已发布,但在 google play 中找不到 2022-01-01
- Android:对话框关闭而不调用关闭 2022-01-01
- 如何在 UIImageView 中异步加载图像? 2022-01-01
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01