Getting an existing NSLayoutConstraint for the width?

前端 未结 3 662
自闭症患者
自闭症患者 2021-02-02 14:40

I\'m trying to animate a control in Cocoa with auto layout.

Now, I can set [[constraint animator] setConstant:newWidth];, which works. But how can I get the

3条回答
  •  灰色年华
    2021-02-02 15:10

    Here is the swift 3 version tested on Xcode 8.2.1 and macOS 10.12.2.

    The code shows how to get a button's width and height constraints, but you could filter whatever you want from NSLayoutAttribute enum.

    let cons = signInButton.constraints.filter {
        $0.firstAttribute == NSLayoutAttribute.width || $0.firstAttribute == NSLayoutAttribute.height /// or other from `NSLayoutAttribute`
    }
    // do something with the constraints array, e.g.
    NSLayoutConstraint.deactivate(cons)
    

提交回复
热议问题