gpt4 book ai didi

ios - 旋转时调用两次 layoutSubviews

转载 作者:可可西里 更新时间:2023-11-01 03:36:47 27 4
gpt4 key购买 nike

当我的主视图旋转时,我想重新安排 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/

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