Autolayout is not updating frames instantly in iOS8-Xcode6

心不动则不痛 提交于 2019-12-06 16:14:20

Auto layout doesn't give you the "right" frame sizes until a layout pass has happened. viewDidLoad is too early, and off the top of my head willAppear might be too. viewDidLayoutSubviews is the right place.

Place this code in your viewDidLoad()

self.view.setNeedsLayout();
self.view.layoutIfNeeded();

Before accessing scorllView.frame.size.width

From the viewDidLoad and viewWillAppear its shows same as interface builder's dimensions. if you apps relay on scrollView frame(if you want them before viewDidAppear) call viewController instance view method before it presenting.

UIViewController *myVC = [[UIViewController alloc]init];
[myVC view]
[self.navigationController pushViewController:myVC];

But this counting on apps performance.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!