在按钮的 touchUpInside 上,它运行一系列代码(所有数据相关,主函数中的代码都没有修改 View 对象)代码所做的最后一件事是调用我粘贴在下面的动画函数.问题是,动画看起来不尽如人意。
想要的动画:
- footerImg 应该淡出
- footerBar 文本应该淡入
- footerBar 文本应该淡出
- footerImg 应该淡入
文本和图像在屏幕上占据相同的位置,所以视觉上应该是一个替换另一个,然后又回到原来的状态。 View 不相互嵌套,它们共享同一个容器。
在模拟器中看到的实际动画:
-footerImg 永远不会出现 -footerBar 文本在点击触发器后立即出现,没有动画 -footerBar 文本淡出 -footerImg 淡入
footerBar 是一个 UIButton
-开始状态,在 Action 开始之前,按钮是空的且清晰(用户不可见)
-以防万一,这不是触发功能的按钮
-有一个清晰的背景,所以它的文字应该是唯一动画进/出的东西
footerImg 是一个 UIImageView
-只是一个图标图片,没什么特别的
func animateFeedback() {
UIView.animateWithDuration(0.25, delay: 0.0, usingSpringWithDamping: 1.0, initialSpringVelocity: 0, options: nil, animations: {
self.footerImg.alpha = 0
self.footerBar.alpha = 0
},
completion: { finished in
self.footerBar.setTitle("Item added", forState: UIControlState.Normal)
}
)
UIView.animateWithDuration(1.5, delay: 0.5, options: nil, animations: {
self.footerBar.alpha = 1
}
, completion: nil
)
UIView.animateWithDuration(0.75, delay: 1.25, options: nil, animations: {
self.footerBar.alpha = 0
}
, completion: { finished in
self.footerBar.setTitle("", forState: UIControlState.Normal)
}
)
UIView.animateWithDuration(0.25, delay: 1.5, options: nil, animations: {
self.footerImg.alpha = 1
}
, completion: nil
)
}
最佳答案
对于序列动画,您应该将动画放在完成 block 中。例如
页脚栏文本应淡入
页脚栏文本应该淡出
试试这个:
self.footerBar.alpha = 0;
UIView.animateWithDuration(1.5, delay: 0.5, options: nil, animations: {
self.footerBar.alpha = 1
}
, completion: { finished in
UIView.animateWithDuration(0.75, delay: 1.25, options: nil, animations: {
self.footerBar.alpha = 0
}
, completion: { finished in
self.footerBar.setTitle("", forState: UIControlState.Normal)
}
)
}
)
其他人也一样
关于ios - UIButton 文本动画不动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32115215/