iOS AutoLayout - get frame size width(iOS AutoLayout - 获取帧大小宽度)
问题描述
我正在使用 iOS 6 自动布局进行开发
I am developing using iOS 6 auto layout
我想记录一条显示视图框架宽度的消息.
I would like to log a message displaying the frame width of the view.
我可以在屏幕上看到 textView.
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
推荐答案
我认为自动布局在你调用它的时候还没有时间来布局你的视图.在调用 viewDidLoad
时自动布局还没有发生,因为它是在视图加载后调用的,并且只有在视图被放置到视图控制器的视图层次结构中并最终布局之后(在视图的 layoutSubviews
方法中).
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).
这个答案指出了为什么问题中的场景不起作用.@dreamzor 的回答指出了将代码放置在何处以解决问题.
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 AutoLayout - 获取帧大小宽度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:iOS AutoLayout - 获取帧大小宽度


基础教程推荐
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01
- 如何在 UIImageView 中异步加载图像? 2022-01-01
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01
- Android:对话框关闭而不调用关闭 2022-01-01
- android 应用程序已发布,但在 google play 中找不到 2022-01-01
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01