【发布时间】:2017-09-26 10:40:33
【问题描述】:
我正在尝试将 visualEffect 添加到在 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 方面的任何内容。
【问题讨论】: