【问题标题】:Trying change Button Title and label.center.x in UIView.animate when press button but stuck. Why? Swift 4 Xcode 9.4当按下按钮但卡住时,尝试在 UIView.animate 中更改按钮标题和 label.center.x。为什么?斯威夫特 4 Xcode 9.4
【发布时间】:2019-02-04 11:01:19
【问题描述】:

我的问题

我正在尝试在 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)
    }
}

It work

但是当我添加 .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)
    }
}

It stuck, only the title of button confirm change, the underline doesn't move

请任何人解释一下这种情况。

编辑:

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

【问题讨论】:

  • 你能把标题设置成另一个字符串,比如“hello”吗?
  • 是的,我可以,意思是用越南语登录和注册
  • 我要问的是:当您使用仅具有拉丁字形的字符串时,应用程序是否可以正常工作?
  • 我全部改成了拉丁字形(例如:setTitle("ok") all of above and mainboard)但它仍然是

标签: swift button label xcode9.4


【解决方案1】:

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

【讨论】:

    【解决方案2】:

    尝试完成“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)
    
    
            }
    

    【讨论】:

    • 我做到了,但没有任何改变
    猜你喜欢
    • 2015-04-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-02-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多