作者热门文章
- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
当我的主视图旋转时,我想重新安排 subview ,所以在我的 ViewController 中,我重写了
willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)orientation duration:(NSTimeInterval)duration
并在那里设置 subview 的框架。这一切都很好,但在 subview 中我也覆盖了
layoutSubviews
所以他们正确地布局自己。但问题是这现在被调用了两次 - 大概是当我在 willAnimateRotationToInterfaceOrientation 中设置 Frame 时一次,一次是因为旋转。 (如果我不设置框架,它会被调用一次。)
肯定是 ViewController 负责布局框架,所以这看起来像是一个设计缺陷 - 有什么解决方案可以让 layoutSubviews 只调用一次?
最佳答案
我也有同样的疑问。我找到了 this page对我有帮助。这对你有用吗?
编辑:以下是页面摘要(已复制):
- init does not cause layoutSubviews to be called (duh)
- addSubview causes layoutSubviews to be called on the view being added, the view it’s being added to (target view), and all the subviews of the target view
- setFrame intelligently calls layoutSubviews on the view having it’s frame set only if the size parameter of the frame is different
- scrolling a UIScrollView causes layoutSubviews to be called on the scrollView, and it’s superview
- rotating a device only calls layoutSubview on the parent view (the responding viewControllers primary view)
- removeFromSuperview – layoutSubviews is called on superview only (not show in table)
关于ios - 旋转时调用两次 layoutSubviews,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14592587/
我是一名优秀的程序员,十分优秀!