iOS的自动版式 - 获得帧大小宽度 [英] iOS AutoLayout - get frame size width

查看:140
本文介绍了iOS的自动版式 - 获得帧大小宽度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是iOS 6的自动布局发展

我想记录的消息显示视图的边框宽度。

我可以在屏幕上看到的TextView的。

但我得到的宽度和高度为零,我失去的东西吗?

 的NSLog(@的TextView =%P,self.textView);
的NSLog(@高度=%F,self.textView.frame.size.height);
的NSLog(@WIDTH =%F,self.textView.frame.size.width);的TextView = 0x882de00
高度= 0.000000
宽度= 0.000000


解决方案

我觉得汽车布局一直没有被你调用这个时间来布置你的意见的时间。自动布局不是由时间 viewDidLoad中被称为发生了,因为它就是所谓的意见被加载刚过,并在那之后,该意见被放入视图控制器的视图层次结构,并最终奠定了(在视图的 layoutSubviews 法)。

编辑:这样的回答指出,为什么在这个问题的方案是行不通的。 @ dreamzor的回答指出在何处放置code,以解决这个问题。

I am developing using iOS 6 auto layout

I would like to log a message displaying the frame width of the view.

I can see the textView on the screen.

But I get the width and height as zero, am I missing something ?

NSLog(@"textView    = %p", self.textView);
NSLog(@"height      = %f", self.textView.frame.size.height);
NSLog(@"width       = %f", self.textView.frame.size.width);

textView    = 0x882de00
height      = 0.000000
width       = 0.000000

解决方案

I think auto layout hasn't had the time to layout your views by the time you call this. Auto layout hasn't happened by the time viewDidLoad is called, because it's called just after the views are loaded and it's only after that that the views are placed into the view controller's view hierarchy and eventually laid out (in the view's layoutSubviews method).

Edit: this answer points out why the scenario in the question doesn't work. @dreamzor's answer points out where to place your code in order to solve it.

这篇关于iOS的自动版式 - 获得帧大小宽度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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