【发布时间】:2018-03-28 01:16:10
【问题描述】:
UIButton 动画标题位置突然改变(向左跳),我想将标题始终保持在附近的按钮中心。
可以看到按钮标题(“登录”)意外跳到左边,应该优化一下。
代码如下:
UIView.animate(withDuration: 1.5, delay: 0.0, usingSpringWithDamping: 0.2, initialSpringVelocity: 0.0, options: [], animations: {
self.loginButton.bounds.size.width -= 80.0
}){ (yes) in }
UIView.animate(withDuration: 0.33, delay: 0.0, usingSpringWithDamping: 0.7, initialSpringVelocity: 0.0, options: [], animations: {
self.loginButton.center.y -= 60.0
self.loginButton.backgroundColor = UIColor(red: 0.63, green: 0.84, blue: 0.35, alpha: 1.0)
self.spinner.center = CGPoint(x: -20, y: -16)
self.spinner.alpha = 0.0
}){ (yes) in }
这是我试过的代码,它也不起作用。
UIView.animate(withDuration: 0.3, delay: 0.2, options: [], animations: {
self.loginButton.backgroundColor = UIColor(red: 0.63, green: 0.84, blue: 0.35, alpha: 1.0)
self.loginButton.bounds.size.width -= 80.0
self.loginButton.center.y -= 60.0
self.spinner.frame.origin = CGPoint(x: -20, y: 16)
self.spinner.alpha = 0.0
}) { (isOK) in }
PS:
我通过storyboard添加登录按钮,如下图
相关代码是here
【问题讨论】:
-
如何添加登录按钮?上传添加登录按钮的代码
-
信息更新@JD。