通过转换设置动画后,我的UIButton停止可单击

时间:2019-06-09 09:09:19

标签: swift animation uiview uibutton

我有一个uiview,单击“ registerSerialNumberButton”按钮后,我要在其中添加一些动画元素。

按钮本身也可以设置动画,并获得一个新的.addtarget,但问题是该按钮变得不可点击。它是可见的,并且我可以明显地更改每个属性。但是无法再单击该按钮。

我尝试将Alpha值设置为更高的值,但这没有用。我还尝试将按钮的框架向上移动,但这似乎也不影响可单击性。

我还尝试添加.isEnabled = true ...不起作用

这是按钮的创建

    let registerSerialNumberButton: UIButton = {
        let button = UIButton(type: .system)
        button.setTitle("Register my nano", for: .normal)
        button.backgroundColor = UIColor.rgb(red: 17, green: 154, blue: 237)
        button.layer.cornerRadius = 10
        button.titleLabel?.font = UIFont.systemFont(ofSize: 16, weight: .medium)
        button.setTitleColor(UIColor.white, for: .normal)
        button.addTarget(self, action: #selector(startEditingSerialNumberInput), for: .touchUpInside)
        button.isEnabled = true
        button.constrainHeight(constant: 60)
        return button
    }()

这是第一次单击时调用的功能

    @objc func startEditingSerialNumberInput() {
        animateRegisterFormUp()
        self.registerSerialNumberButton.addTarget(self, action: #selector(self.saveSerialNumberFunction), for: .touchUpInside)
    }

这是动画功能

    func animateRegisterFormUp() {
        UIView.animate(withDuration: 0.72, delay: 0, usingSpringWithDamping: 0.7, initialSpringVelocity: 0.7, options: .curveEaseInOut, animations: {
            self.registerTitlelabel.transform = .init(translationX: 0, y: -100)
            self.registerdescriptionLabel.transform = .init(translationX: 0, y: -100)
            self.serialnumberInput.transform = .init(translationX: 0, y: -100)
            self.registerSerialNumberButton.transform = .init(translationX: 0, y: -140)
            self.registerSerialNumberButton.backgroundColor = .red
            self.registerSerialNumberButton.addTarget(self, action: #selector(self.saveSerialNumberFunction), for: .touchUpInside)
            self.registerSerialNumberButton.isUserInteractionEnabled = true
        }, completion: nil)
    }

编辑

我使用stackview将按钮加载到视图中。

            let stackviewButtons = UIStackView(arrangedSubviews: [registerSerialNumberButton, dothislaterButton])
            stackviewButtons.axis = .vertical
            stackviewButtons.alignment = .fill
            stackviewButtons.spacing = 10

            let stackview = UIStackView(arrangedSubviews: [registerTitlelabel, registerdescriptionLabel, serialnumberInput, stackviewButtons])
            stackview.axis = .vertical
            stackview.spacing = 20
            stackview.setCustomSpacing(40, after: registerdescriptionLabel)
            stackview.setCustomSpacing(100, after: serialnumberInput)
            view.addSubview(stackview)
            stackview.anchor(top: nil, left: view.leftAnchor, bottom: nil, right: view.rightAnchor, paddingTop: 0, paddingLeft: 20, paddingBottom: 0, paddingRight: 20, width: 0, height: 0)
            stackview.centerXInSuperview()
            stackview.centerYInSuperview()

0 个答案:

没有答案