0

I updated Xcode 8 and SnapKit 3.0 to test auto layout. I can get frame correct after call layoutIfNeeded before i update to SnapKit 3.0. But i get frame.origin.x and .y both negative value now under SnapKit 3.0.

example:

        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
William Hu
  • 15,423
  • 11
  • 100
  • 121

1 Answers1

0

You need to call layoutIfNeeded on view rather than signUpView as it is the container that needs to do the layout pass.

Robert Payne
  • 278
  • 2
  • 6