我只是好奇,关于初始化 UIView
s;我注意到,当我调用实例构造函数 -(id)initWithFrameCGRect)frame
时,从未真正调用原始构造函数 -(id)init
,这意味着我必须在两个构造函数中初始化实例变量。这是否意味着一种优化策略,使得调用 -(id)initWithFrameCGRect)frame
在计算上比调用 UIView *view = [UIView new 在计算上“更快”(鼓励更好的性能) ]; view.frame = 框架;
? initWithFrame 选项是否比创建新实例并手动分配其框架更快?我实际上更喜欢使用后者来保持程序的一致性。
不,只是 initWithFrame
是 UIView
的指定初始化程序(来自 class reference):
Discussion
The new view object must be inserted into the view hierarchy of a window before it can be used. If you create a view object programmatically, this method is the designated initializer for the UIView class. Subclasses can override this method to perform any custom initialization but must call super at the beginning of their implementation.
关于ios - initWithFrame 比 view.frame 快?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25203197/
欢迎光临 OStack程序员社区-中国程序员成长平台 (https://ostack.cn/) | Powered by Discuz! X3.4 |