• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

ios - initWithFrame 比 view.frame 快?

[复制链接]
菜鸟教程小白 发表于 2022-12-12 11:12:54 | 显示全部楼层 |阅读模式 打印 上一主题 下一主题

我只是好奇,关于初始化 UIViews;我注意到,当我调用实例构造函数 -(id)initWithFrameCGRect)frame 时,从未真正调用原始构造函数 -(id)init,这意味着我必须在两个构造函数中初始化实例变量。这是否意味着一种优化策略,使得调用 -(id)initWithFrameCGRect)frame 在计算上比调用 UIView *view = [UIView new 在计算上“更快”(鼓励更好的性能) ]; view.frame = 框架;? initWithFrame 选项是否比创建新实例并手动分配其框架更快?我实际上更喜欢使用后者来保持程序的一致性。



Best Answer-推荐答案


不,只是 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/

回复

使用道具 举报

懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关注0

粉丝2

帖子830918

发布主题
阅读排行 更多
广告位

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap