gpt4 book ai didi

objective-c - UIScrollView 每次滚动时调用 layoutSubviews()

转载 作者:太空狗 更新时间:2023-10-30 03:36:22 27 4
gpt4 key购买 nike

我继承了 UIScrollView (IPhone SDK) 并覆盖了 (void)layoutSubviews;方法。我注意到每次滚动 scrollView 时,都会调用此方法。

这是正确的行为还是我的代码有错误?如果这是默认行为,这不是性能 killer 吗?

真诚的,海因里希

最佳答案

这是正确的行为,应该用于获取 subview 的自定义布局。我已经使用了好几次,即使添加了数百个项目也没有出现任何性能问题。

documentation 的截图关于那个主题:

Subclasses can also be containers for other views. In this case, just override the designated initializer, initWithFrame:, to create a view hierarchy. If you want to programmatically force the layout of subviews before drawing, send setNeedsLayout to the view. Then when layoutIfNeeded is invoked, the layoutSubviews method is invoked just before displaying. Subclasses should override layoutSubviews to perform any custom arrangement of subviews.

关于objective-c - UIScrollView 每次滚动时调用 layoutSubviews(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2760309/

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