【问题标题】:iochanging slid-in and slid-out animation to fade-in and fade-out in SWRevealViewController在 SWRevealViewController 中将滑入和滑出动画更改为淡入和淡出
【发布时间】:2018-08-09 08:32:32
【问题描述】:
我在左侧菜单中使用SWRevealViewController,我想更改默认动画并制作淡出动画。我尝试了他们的代表,如下所示,但没有成功。
func revealController(_ revealController: SWRevealViewController!, animateTo position: FrontViewPosition) {
if position == .left {
view.alpha = 0.15
}
else if position == .right {
view.alpha = 1
}
}
【问题讨论】:
标签:
swift
uiviewcontroller
uiviewanimation
swrevealviewcontroller
【解决方案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()
}
}
【解决方案2】:
查看this tutorial!
或者你可以试试这个
revealViewController.toggleAnimationType = SWRevealToggleAnimationTypeEaseOut