我在左侧使用SWRevealViewController
菜单,我想更改默认动画并制作淡出动画。我尝试了他们的代表如下,但它没有成功。
func revealController(_ revealController: SWRevealViewController!, animateTo position: FrontViewPosition) {
if position == .left {
view.alpha = 0.15
}
else if position == .right {
view.alpha = 1
}
}
答案 0 :(得分: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()
}
}
答案 1 :(得分:1)
或者你可以试试这个
revealViewController.toggleAnimationType = SWRevealToggleAnimationTypeEaseOut