gpt4 book ai didi

swift - iochanging 滑入和滑出动画以在 SWRevealViewController 中淡入和淡出

转载 作者:可可西里 更新时间:2023-11-01 01:09:20 26 4
gpt4 key购买 nike

我正在为左侧菜单使用 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com