为什么此代码会导致 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,而 UIButton 确实有 setAlpha。
这是我的属性:
@IBOutlet weak var btnShowDial: UIButton!
@IBOutlet weak var lcDialBottom: NSLayoutConstraint!
最佳答案
检查 Storyboard 中 btnShowDial 的连接。也许您用布局约束连接了这个 IBOutlet。
关于Swift:动画 uilayoutconstraints 和更改 alpha 会导致崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52873885/