gpt4 book ai didi

ios - 具有透明背景的 UIModalPresentationFormSheet?

转载 作者:可可西里 更新时间:2023-11-01 05:31:48 24 4
gpt4 key购买 nike

基本上,我希望模态表单是透明的,这样我就可以看到它后面的 UIView(它是全屏的)。

这可能吗?将 UIView 设置为不透明并且 [UIColor clearColor]backgroundColor 不起作用。

我注意到当我从 UIModalPresentationFormSheet 切换到另一种演示风格时,我的 View 背景确实是透明的。

我哪里做错了?

最佳答案

这对我有用:

[modalView.superview setBackgroundcolor:[UIColor clearColor]];

它仍然会透明地使背景 View 变暗,但不会用纯灰色覆盖它。

................................................

iOS 8 更新

我以前的解决方案不再适用于 iOS 8。有很多步骤可以让这样的东西在 iOS 8 上工作。所以我创建了一个很好的可重用解决方案:ModalController https://github.com/koreyhinton/ModalController .

它真的很容易使用并且会自动关闭。

let modal = ModalController()
modal.content = myCustomView
presentViewController(modal, animated: true, completion: nil)

如果您对实现细节感兴趣,我就是这样做的:

让模态视图 Controller 占据整个屏幕,主视图的背景将在透明和半暗之间切换。然后,您将拥有一个内容 View ,该 View 将是模式,它将以纯色背景为中心。我还使用了演示样式:.OverCurrentContext,我在 init 方法中分配了它。

var content = UIView()

override func viewDidLoad() {
super.viewDidLoad()
view.backgroundColor = UIColor.clearColor()
content.frame = CGRect(x:0, y:0, width:300, height:300)
content.backgroundColor = UIColor.blackColor()
view.addSubview(content)
}

override func viewDidAppear(animated: Bool) {
super.viewDidAppear(animated)
view.backgroundColor = UIColor.blackColor().colorWithAlphaComponent(0.7)
}

override func viewWillDisappear(animated: Bool) {
super.viewWillDisappear(animated)
view.backgroundColor = UIColor.clearColor()
}

override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()

content!.center = view.center
}

关于ios - 具有透明背景的 UIModalPresentationFormSheet?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8828340/

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