gpt4 book ai didi

ios - Swift - 使 UIViewController 可见,同时从 TOP 添加动画的新 ViewController(通过 self.present)

转载 作者:行者123 更新时间:2023-11-28 12:17:17 25 4
gpt4 key购买 nike

我正在尝试从顶部添加一个 View Controller ,因为我已经创建了一个可以正常工作的自定义动画。但是,正在添加的 View Controller 的背景颜色设置为黑色,因为我只是希望它是透明的,以便下面的 View Controller 可见。

这是添加自定义动画的代码:

let vc = Global.sharedInstance.storyboard.instantiateViewController(withIdentifier: "AnimationViewControllerID") as! AnimationViewController
vc.view.backgroundColor = UIColor.clear
vc.personName = name
let begin = CGRect(x: 0, y: -vc.view.frame.height, width: vc.view.frame.width, height: vc.view.frame.height)
let end = CGRect(x: 0, y: 0, width: vc.view.frame.width, height: vc.view.frame.width)
self.present(vc, animated: false) { () -> Void in
vc.view.frame = begin
vc.view.alpha = 0.5
vc.view.backgroundColor = UIColor.clear
UIView.animate(withDuration: 1, animations: { () -> Void in
vc.view.frame = end
},
completion: nil)
}

我尝试将 View Controller 的背景颜色设置为清除,但仍然没有使背景透明。

最佳答案

您应该相应地设置呈现的 View Controller 的呈现样式

如果您希望它显示在当前窗口上,请将其设置为 overFullScreen;如果您只想将其设置在 View Controller 的上下文之上,请将其设置为 overCurrentContext

此外,您应该将 definesPresentationContext 设置为 true

vc.modalPresentationStyle = .overFullScreen
vc.definesPresentationContext = true

关于ios - Swift - 使 UIViewController 可见,同时从 TOP 添加动画的新 ViewController(通过 self.present),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46032909/

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