【问题标题】:Swift: animating uilayoutconstraints and changing alpha causes crashSwift:动画 uilayoutconstraints 和更改 alpha 会导致崩溃
【发布时间】: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


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 2016-03-29
    • 1970-01-01
    • 1970-01-01
    • 2015-08-14
    • 1970-01-01
    • 2016-12-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多