使用CGRectZero在UIView类或子类上调用initWithFrame是什么意思? [英] What does it mean to call initWithFrame on a UIView class or subclass with CGRectZero?

查看:135
本文介绍了使用CGRectZero在UIView类或子类上调用initWithFrame是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我见过调用 uWiew 子类的 initWithFrame 的代码(例如 UILabel CGRectZero ,似乎工作正常。使用2D点实例化 UIView 子类是什么意思(这似乎是 CGRectZero 是什么)? / p>

I have seen code that calls initWithFrame of a UIView subclass (such as UILabel) with CGRectZero and things seem to work fine. What does it mean to instantiate a UIView subclass with a 2D point (which seems to be what CGRectZero is)?

推荐答案

这只是意味着您实例化的视图没有其框架的初始值。

It just means that you're instantiating the view without an initial value for its frame.

例如,当您想要创建视图对象的实例而不需要立即将其放入视图层次结构时,就可以完成此操作。决定和设置框架可以在以后使用setFrame执行:。

This is done, for instance, when you want to create an instance of the view object and do not need to place it into the view hierarchy right away. Deciding upon and setting the frame can be performed at a later time, using setFrame:.

CGRectZero常用于初始化UITableViewCell,在SDK 2.x中。 tableView:cellForRowAtIndexPath:中需要一个视图实例,并且在创建时不需要提供框架,因为表视图将自动定位单元格并使其在以后成为最佳尺寸。

CGRectZero is commonly used when initializing UITableViewCell's, in SDK 2.x that is. An instance of the view is needed in tableView:cellForRowAtIndexPath:, and there's no need to supply the frame upon creation because the table view will automatically position the cell and makes it the optimal size at a later time.

这篇关于使用CGRectZero在UIView类或子类上调用initWithFrame是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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