Plu*_*Boy 19 animation fadeout fadein ios swift
我有一个带有动画的UIImageView,在UIView中,我应用了一个fadeIn效果,但我需要在触摸时动画的UIImageView应用淡出.
这就是我为淡入而做的.
UIView.animateWithDuration(0.5, delay: delay,
options: UIViewAnimationOptions.CurveEaseOut, animations: {
uiImageView.alpha = 1.0
}
Run Code Online (Sandbox Code Playgroud)
小智 46
这是我根据我的研究做的事情:(假设你正在使用故事板)
转到UIImageView,在Attributes下,选中"User Interaction Enabled"复选框.
将TapGestureRecognizer拖动到图像视图的顶部.
控制单击Tap Gesture并拖动以对ViewControler.swift进行操作.
在里面添加以下代码:
UIView.animate(withDuration: 0.5, delay: 0.5, options: .curveEaseOut, animations: {
self.uiImageView.alpha = 0.0
}, completion: nil)
Run Code Online (Sandbox Code Playgroud)那你就完成了!
Olg*_*eva 11
从iOS 10开始,Apple推出了新的iOS动画SDK,它功能更强大,特别是在时序功能和交互性方面.
使用这种方法淡出代码将:
UIViewPropertyAnimator(duration: 0.5, curve: .easeOut, animations: {
self.uiImageView.alpha = 0.0
}).startAnimation()
Run Code Online (Sandbox Code Playgroud)
要获得有关Property Animator的更多详细信息,请查看iOS 10 Animations演示.
Aug*_*Lin 11
斯威夫特4.向UIView对象添加淡入和淡出功能
extension UIView {
func fadeIn(_ duration: TimeInterval = 0.5, delay: TimeInterval = 0.0, completion: @escaping ((Bool) -> Void) = {(finished: Bool) -> Void in}) {
UIView.animate(withDuration: duration, delay: delay, options: UIViewAnimationOptions.curveEaseIn, animations: {
self.alpha = 1.0
}, completion: completion) }
func fadeOut(_ duration: TimeInterval = 0.5, delay: TimeInterval = 1.0, completion: @escaping (Bool) -> Void = {(finished: Bool) -> Void in}) {
UIView.animate(withDuration: duration, delay: delay, options: UIViewAnimationOptions.curveEaseIn, animations: {
self.alpha = 0.3
}, completion: completion)
}
}
Run Code Online (Sandbox Code Playgroud)
例
label.fadeIn()
label.fadeOut()
imageView.fadeOut(completion: {
(finished: Bool) -> Void in
imageView.removeFromSuperview()
})
label.fadeIn(completion: {
(finished: Bool) -> Void in
label.text = "Changed!"
})
Run Code Online (Sandbox Code Playgroud)