不正确使用框架和自动布局被放报告;大小级 [英] Incorrect frame being reported using Autolayout & Size Classes

查看:173
本文介绍了不正确使用框架和自动布局被放报告;大小级的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的UIViewController奠定了一个UIView。约束它的高度和宽度,并与约束垂直和水平居中,但是当我登录的框架,它报告说,似乎是适当充分sizeClass的位置,但不是我期待在​​屏幕的大小。

I've laid out a UIView in my UIViewController. Constrained its height and width, and centered it vertically and horizontally with constraints, but when I log its frame, it reports a location that seems appropriate to the full sizeClass, but not the size of the screen I'm looking at.

例如默认大小类的UIViewController有600px的宽度,并且在尺寸,我UIView是从左侧边缘150像素。当我从左边检查这个距离iPhone5的模拟器运行时,它仍然报告150像素。

For example the default size class UIViewController has a width of 600px, and in that size, my UIView is 150px from the left edge. When I check this distance from the left edge while running in the iphone5 simulator, it still reports 150px.

有关这一切奇怪的是,UIView的本身仍然出现在预期(调整屏幕大小)的位置。

The weird thing about all of this, is that the UIView itself still appears in the expected (adjusted for screen-size) location.

推荐答案

有关后人:我是有这个问题 - 打印视图帧时得到不正确的价值观 - 是由在<访问该帧引起的code> viewDidLoad中。是在在的ViewController的生命周期至此所有的观点可能尚未布局。

For posterity: the problem I was having -- getting incorrect values when printing the frame of a view -- was caused by accessing that frame during ViewDidLoad. At this point in the ViewController lifecycle all views may have not been laid out.

因此​​,最安全后才 ViewDidLayoutSubviews 被称为访问的UIView 财产/出口。

Therefore, it is safest to access a UIView property/outlet only after ViewDidLayoutSubviews has been called.

我的意思是,这是正确的,在方法的名字:你的意见已制定了......现在做的东西他们。

I mean, it's right there in the name of the method: "Your views have been laid out... now do stuff with them."

这篇关于不正确使用框架和自动布局被放报告;大小级的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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