UIButton 文本动画不动画
UIButton Text Animation Not Animating
在按钮的 touchUpInside 上,它运行一系列代码(所有数据相关,主函数中的代码 none 修改视图对象)代码做的最后一件事是调用动画函数我在下面粘贴了。问题是,动画看起来不尽如人意。
想要的动画:
- footerImg 应该淡出
- footerBar 文本应该淡入
- footerBar 文本应该淡出
- footerImg 应该淡入
文本和图像在屏幕上占据相同的位置,所以视觉上应该是一个替换另一个,然后又回到原来的状态。视图不相互嵌套,它们共享同一个容器。
在模拟器中看到的实际动画:
-footerImg 从来都不可见
-footerBar 文本在点击触发器后立即出现,没有动画
-footerBar 文本淡出
-footerImg 淡入
footerBar 是一个 UIButton
-开始状态,在动作开始之前,按钮是空的且清晰(用户不可见)
-以防万一,这不是触发功能的按钮
-有清晰的背景,所以它的文字应该是唯一的动画 in/out
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
)
}
对于序列动画,你应该把动画放在完成块后面。例如
footerBar 文本应该淡入
footerBar 文本应该淡出
试试这个:
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)
}
)
}
)
其他人也一样
评论你在"animateFeedback()"中的所有代码并将下面的代码粘贴到其中
UIView.animateWithDuration(1.5, delay: 0, options: nil, animations: { () -> Void in
self.footerImg.alpha = 0;
self.footerBar.setTitle("Item added", forState: UIControlState.Normal)
},
completion: { finished in
UIView.animateWithDuration(1.5, delay: 0, options: nil, animations: { () -> Void in
self.footerImg.alpha = 1;
self.footerBar.setTitle("", forState: UIControlState.Normal)
},
completion: { finished in
}
)
}
)
在按钮的 touchUpInside 上,它运行一系列代码(所有数据相关,主函数中的代码 none 修改视图对象)代码做的最后一件事是调用动画函数我在下面粘贴了。问题是,动画看起来不尽如人意。
想要的动画:
- footerImg 应该淡出
- footerBar 文本应该淡入
- footerBar 文本应该淡出
- footerImg 应该淡入
文本和图像在屏幕上占据相同的位置,所以视觉上应该是一个替换另一个,然后又回到原来的状态。视图不相互嵌套,它们共享同一个容器。
在模拟器中看到的实际动画:
-footerImg 从来都不可见 -footerBar 文本在点击触发器后立即出现,没有动画 -footerBar 文本淡出 -footerImg 淡入
footerBar 是一个 UIButton
-开始状态,在动作开始之前,按钮是空的且清晰(用户不可见)
-以防万一,这不是触发功能的按钮
-有清晰的背景,所以它的文字应该是唯一的动画 in/out
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
)
}
对于序列动画,你应该把动画放在完成块后面。例如
footerBar 文本应该淡入
footerBar 文本应该淡出
试试这个:
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)
}
)
}
)
其他人也一样
评论你在"animateFeedback()"中的所有代码并将下面的代码粘贴到其中
UIView.animateWithDuration(1.5, delay: 0, options: nil, animations: { () -> Void in
self.footerImg.alpha = 0;
self.footerBar.setTitle("Item added", forState: UIControlState.Normal)
},
completion: { finished in
UIView.animateWithDuration(1.5, delay: 0, options: nil, animations: { () -> Void in
self.footerImg.alpha = 1;
self.footerBar.setTitle("", forState: UIControlState.Normal)
},
completion: { finished in
}
)
}
)