gpt4 book ai didi

ios - 使用自定义动画的弹出 Controller 后屏幕变黑

转载 作者:行者123 更新时间:2023-11-28 13:52:10 24 4
gpt4 key购买 nike

我正在尝试使用呈现 Controller 和弹出 Controller (如关闭)的动画来插入 Controller 。

我正在使用这段代码来推送 Controller

    let transition:CATransition = CATransition()
transition.duration = 0.4
transition.timingFunction = CAMediaTimingFunction(name: CAMediaTimingFunctionName.linear)
transition.type = CATransitionType.moveIn
transition.subtype = CATransitionSubtype.fromTop
AppDelegate.shared.window?.rootViewController!.view.layer.add(transition, forKey: kCATransition)
self.push(articleDetailScene, animated: false)

并使用此代码弹出。

    let transition:CATransition = CATransition()
transition.duration = 0.0
transition.timingFunction = CAMediaTimingFunction(name: CAMediaTimingFunctionName.easeOut)
transition.type = CATransitionType.reveal
transition.subtype = CATransitionSubtype.fromBottom
self.navigationController?.view.layer.add(transition, forKey: kCATransition)
self.pop(animated: false)

放置 Controller 后,屏幕底部出现黑屏。我用过这个answers但这会为那个空间创建一个白屏,而不是在那个空间显示我的单元格。 Black screen when I don't use window background color to whiteWhen I set window background color to white .

最佳答案

您可以试试这个示例代码。

我正在添加过渡到 self.view 的窗口而不是 AppDelegate 的窗口

我有基础 View Controller 并有以下方法

func addTransitionForPush () {
let transition = CATransition()
transition.duration = 0.55
transition.type = CATransitionType.push
transition.subtype = CATransitionSubtype.fromBottom
transition.fillMode = CAMediaTimingFillMode.forwards
view.window?.layer.add(transition, forKey: kCATransition)
}


func addTransitionForPop () {
let transition = CATransition()
transition.duration = 0.55
transition.type = CATransitionType.push
transition.subtype = CATransitionSubtype.fromTop
transition.fillMode = CAMediaTimingFillMode.backwards
view.window?.layer.add(transition, forKey: kCATransition)
}

我如何在我的 View Controller 中使用它

用于推送 VC

@objc private func btnFilterTapped() {
self.addTransitionForPush()
let vc = self.storyboard........
self.navigationController?.pushViewController(vc, animated: false)
}

弹出

    self.addTransitionForPop()
self.navigationController?.popViewController(animated: false)

如果您仍然遇到黑屏问题,请告诉我。

关于ios - 使用自定义动画的弹出 Controller 后屏幕变黑,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54421982/

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