gpt4 book ai didi

ios - initWithFrame 比 view.frame 快?

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:04:24 24 4
gpt4 key购买 nike

我只是好奇,在初始化 UIView 时;我注意到当我调用实例构造函数 -(id)initWithFrame:(CGRect)frame 时,原始构造函数 -(id)init 从未真正被调用,这意味着我必须在两个构造函数中初始化实例变量。这是否意味着调用 -(id)initWithFrame:(CGRect)frame 比调用 UIView *view = [UIView new ]; view.frame = frame;? initWithFrame 选项是否比创建新实例并手动分配其框架更快?我实际上更喜欢做后者以保持程序的一致性。

最佳答案

不,只是 initWithFrameUIView指定初始化程序(来自 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com