0

我的问题

我正在尝试在 touchInside button 时使用 UIView.animate(..) 做一些带有标签的动画。在我添加一行之前,一切都还可以:“self?.confirm.setTitle("Đăng nhập", for: .normal)。动画不起作用。

我的意志

我希望Đăng Ký下方的黄色下划线切换到Đăng nhập下方。

代码是很好的

@IBAction func signUpAction(_ sender:Any?){
    if (signup == false){
        signup = true
        UIView.animate(withDuration: 0.4, delay: 0, options: [.curveEaseIn], animations: {[weak self] in
            self?.underlineSignup.center.x -= (self?.underlineSignup.bounds.width)!
           self?.view.layoutIfNeeded()
        }, completion: nil)
    }
}
@IBAction func signInAction(_ sender:Any?){
    if (signup == true){
        signup = false
        UIView.animate(withDuration: 0.4, delay: 0, options: [.curveEaseIn], animations: {[weak self] in
            self?.underlineSignup.center.x += (self?.underlineSignup.bounds.width)!
            self?.view.layoutIfNeeded()
        }, completion: nil)
    }
}

这行得通

但是当我添加 .setTitle

@IBAction func signUpAction(_ sender:Any?){
    if (signup == false){
        signup = true
        UIView.animate(withDuration: 0.4, delay: 0, options: [.curveEaseIn], animations: {[weak self] in
            self?.underlineSignup.center.x -= (self?.underlineSignup.bounds.width)!
            self?.confirm.setTitle("Đăng ký", for: .normal)
            self?.view.layoutIfNeeded()
        }, completion: nil)
    }
}
@IBAction func signInAction(_ sender:Any?){
    if (signup == true){
        signup = false
        UIView.animate(withDuration: 0.4, delay: 0, options: [.curveEaseIn], animations: {[weak self] in
            self?.underlineSignup.center.x += (self?.underlineSignup.bounds.width)!
            self?.confirm.setTitle("Đăng nhập", for: .normal)
            self?.view.layoutIfNeeded()
        }, completion: nil)
    }
}

卡住了,只有按钮确认更改的标题,下划线不动

请任何人都可以解释这种情况。

编辑:

动画工作但它的目的地总是在Đăng ký下的第一位(动画来自它的左侧或右侧,结果总是第一位)

4

2 回答 2

0

尝试完成“setTitle”。

UIView.animate(withDuration: 0.15, delay: 0, options: .curveLinear, animations: {

       self?.underlineSignup.center.x -= (self?.underlineSignup.bounds.width)!
       self?.view.layoutIfNeeded()

        }){

               //completion
             self?.confirm.setTitle("Đăng ký", for: .normal)


        }
于 2018-08-30T04:10:21.307 回答
0

我想我知道它是怎么回事。因为在 setTitle 有 updateFrame Constraintlayout 的视图。构建按钮时我有一个约束布局。当我 setTitles 它使用约束重置视图。我就是这么想的。

于 2018-08-29T17:03:23.643 回答