gpt4 book ai didi

ios - LoadVIew() 中的 UIVisualEffectView

转载 作者:行者123 更新时间:2023-11-28 19:29:52 27 4
gpt4 key购买 nike

我正在尝试将 visualEffect 添加到 View 中,该 View 在 iOS10 和之前的版本上运行良好……但在 iOS 11 上它崩溃了。错误原因如下:

 has been added as a subview to <UIVisualEffectView: 0x7feabe90d170; frame = (0 0; 375 812); layer = <CALayer: 0x6000006257c0>>. Do not add subviews directly to the visual effect view itself, instead add them to the -contentView."

我正在使用以下代码:

 override func loadView() { 
super.loadView()

// create the blur view
let blurView = UIVisualEffectView(effect: effect)
if let oldView = view {
blurView.frame = view.frame
oldView.translatesAutoresizingMaskIntoConstraints = false
blurView.contentView.addSubview(oldView)
blurView.contentView.pinParentAllDirections(oldView)
}
view = blurView
}

奇怪的是,当我在 viewDidload 中添加此代码时,它正在通过崩溃...任何人请帮助我理解主要问题,或者我是否遗漏了 iOS11 方面的任何内容。

最佳答案

我们不应该从 loadView 函数调用 super.loadView()

https://developer.apple.com/documentation/uikit/uiviewcontroller/1621454-loadview

If you use Interface Builder to create your views and initialize the view controller, you must not override this method.

我们有类似的东西并通过将代码移出 loadView 方法来修复它。因为 loadView 用于构建 View ,而不是您要自定义 View 的时间点。

关于ios - LoadVIew() 中的 UIVisualEffectView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46424215/

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