【发布时间】:2018-10-18 12:20:08
【问题描述】:
为什么此代码会导致 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!
【问题讨论】:
-
也许您将 btnShowDial 与布局约束相关联?在情节提要中检查它。
-
你是对的。让它成为一个答案,我会给你一个凹凸!谢谢!
标签: swift animation nslayoutconstraint