【问题标题】:Xcode 8 return height= 1000 and Width =1000 for UIview (actual size is (328,40))Xcode 8 为 UIview 返回 height= 1000 和 Width =1000 (实际大小为(328,40))
【发布时间】:2017-01-28 10:09:28
【问题描述】:

自从我安装了 Xcode 8,我遇到了麻烦。 我没有得到每个或任何 UIView 的正确值。

我还收到了 UIView 的约束警报。所以我更新它。 但是视图返回 1000 作为宽度或高度。 我尝试或搜索了很多。但没有得到任何适当的解决方案。 请帮助我。

【问题讨论】:

    标签: uiview height width


    【解决方案1】:

    在 xcode 8 中,我无法让 layoutIfNeeded 完全正常工作,因此我不得不将情节提要保存为 Xcode 7 文件。但是,这个问题似乎在 xcode8.1 中得到修复 see this comment here

    【讨论】:

      【解决方案2】:

      对于 Swift 3

      override func viewDidLoad() {
          super.viewDidLoad()
          self.view.layoutIfNeeded()
      }
      

      【讨论】:

        【解决方案3】:

        here 所述,您应致电layoutIfNeeded 以在viewDidLoad 中查看:

        - (void)viewDidLoad
        {
            [super viewDidLoad];
        
            [self.view layoutIfNeeded];
        
            // Now all your subviews are sized as you expect
        }
        

        【讨论】:

        • 谢谢你..我会试试这个。
        • 它适用于我的 swift - self.view.layoutIfNeeded()
        • 不适用于 textView inputAccessoryView。但我想我可以在设置 inputAccessoryView 之前手动设置框架......但我讨厌硬代码:(
        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-10-09
        • 2016-08-20
        • 1970-01-01
        • 2017-03-30
        • 1970-01-01
        相关资源
        最近更新 更多