Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在使用几个不同的视图,一个是图像视图,另一个是标签。我必须在代码中使用帧大小值(宽度和高度),但它们返回的值为零。当我查看故事板中的设置时,显然不是这种情况,但是当我将值记录到控制台时,它们为零。有谁知道这可能是什么原因造成的?
您的插座未连接,或者您的视图尚未实例化,因为您在视图生命周期中太早了。尝试您的日志语句viewDidLoad并viewDidAppear进行比较。
viewDidLoad
viewDidAppear
frame 和 bounds 的区别在于 frame 用 superview 的坐标表示。由于您只需要大小,因此如果视图没有超级视图,则不应考虑它的框架,而是边界:
@property(nonatomic) CGRect bounds;
参考:
http://developer.apple.com/library/ios/#documentation/uikit/reference/uiview_class/uiview/uiview.html