作者热门文章
- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我正在为左侧菜单使用 SWRevealViewController
,我想更改默认动画并制作淡出动画。我尝试了他们的委托(delegate),如下所示,但没有成功。
func revealController(_ revealController: SWRevealViewController!, animateTo position: FrontViewPosition) {
if position == .left {
view.alpha = 0.15
}
else if position == .right {
view.alpha = 1
}
}
最佳答案
import Foundation
import UIKit
extension UIView {
func fadeIn(_ duration: TimeInterval = 1.0, 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 = 1.0, delay: TimeInterval = 0.0, completion: @escaping (Bool) -> Void = {(finished: Bool) -> Void in}) {
UIView.animate(withDuration: duration, delay: delay, options: UIViewAnimationOptions.curveEaseIn, animations: {
self.alpha = 0.15
}, completion: completion)
}
}
现在像这样改变你的功能
func revealController(_ revealController: SWRevealViewController!, animateTo position: FrontViewPosition) {
if position == .left {
view.fadeOut()
}
else if position == .right {
view.fadeIn()
}
}
关于swift - iochanging 滑入和滑出动画以在 SWRevealViewController 中淡入和淡出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49046891/
我是一名优秀的程序员,十分优秀!