Swift:为uilayoutconstraints设置动画并更改Alpha会导致崩溃

时间:2018-10-18 12:20:09

标签: swift animation nslayoutconstraint

为什么此代码会导致SIGABT错误?

@IBAction func showDial(_ sender: Any) {

        var dialBottom:CGFloat = lcDialBottom!.constant

        if dialBottom == -600 {
            //move up
            dialBottom = -400
        } else {
            //move down
            dialBottom = -600
        }

        UIView.animate(withDuration: 0.3,
            animations: {
                self.lcDialBottom.constant = dialBottom
                self.view.layoutIfNeeded()
                self.view.updateConstraintsIfNeeded()
                self.btnShowDial.alpha = 0.0
       })
    }

错误:

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSLayoutConstraint setAlpha:]: unrecognized selector sent to instance 0x600002ff8d70'

我理解错误的意思,NSLayoutConstraint没有setAlpha方法,但是我没有在NSLC上调用它,而是在UIButton上调用了set alpha,后者确实具有setAlpha。

这是我的财产:

@IBOutlet weak var btnShowDial: UIButton!
@IBOutlet weak var lcDialBottom: NSLayoutConstraint!

1 个答案:

答案 0 :(得分:0)

在情节提要中检查btnShowDial的连接。也许您将此IBOutlet与布局约束相连。