【问题标题】:Snapkit 3.0 can't get correct frame after call layoutIfNeeded调用 layoutIfNeeded 后 Snapkit 3.0 无法获得正确的帧
【发布时间】:2016-09-18 13:52:54
【问题描述】:

我更新了 Xcode 8SnapKit 3.0 来测试自动布局。在我更新到 SnapKit 3.0 之前,我可以在调用 layoutIfNeeded 后得到正确的帧。但是我现在在 SnapKit 3.0 下得到了 frame.origin.x.y 两个负值。

示例

        let signUpView = UIView()
        view.addSubview(signUpView)
        signUpView.snp.makeConstraints { (make) -> Void in
            make.leading.equalTo(50)
            make.trailing.equalTo(-50)
            make.top.equalTo(topView.snp.bottom)
            make.height.equalTo(50)
        }
        // here frame is: {0,0,0,0}
        signUpView.layoutIfNeeded()

        // here frame is:
            (-137.5, -25.0, 275.0, 50.0)
            ▿ origin : (-137.5, -25.0)
              - x : -137.5
              - y : -25.0
            ▿ size : (275.0, 50.0)
              - width : 275.0
              - height : 50.0

【问题讨论】:

    标签: swift3 snapkit


    【解决方案1】:

    您需要在view 而不是signUpView 上调用layoutIfNeeded,因为它是需要进行布局传递的容器。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-09-05
      • 1970-01-01
      • 2021-03-09
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多