gpt4 book ai didi

ios - 如何在 viewWillTransitionToSize 中获取 safeAreaInsets (iPhone X)

转载 作者:搜寻专家 更新时间:2023-10-30 22:04:32 25 4
gpt4 key购买 nike

我正在尝试为 iPhoneX 更新 viewWillTransition(to size: with coordinator:) 方法。但是我无法获取 safeAreaInsets 值的目的地。请帮忙!

override func viewWillTransition(to size: CGSize,
with coordinator: UIViewControllerTransitionCoordinator) {

super.viewWillTransition(to: size, with: coordinator)

if #available(iOS 11.0, *) {
if let window = UIApplication.shared.keyWindow {
let insets = window.safeAreaInsets
contentFrame = CGRect(x:insets.left, y:insets.top,
width:size.width - insets.left - insets.right,
height:size.height - insets.top - insets.bottom)
}
} else {
contentFrame = CGRect(x:0,y:0,width:size.width, height:size.height)
}
self.updateViews()
}

最佳答案

我在 Stackoverflow Japan 得到了有效的解决方案。

它只是在 UIViewControllerTransitionCoordinator.animate(alongsideTransition:completion:) 闭包中获取 insets,如下所示:

override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
super.viewWillTransition(to: size, with: coordinator)

coordinator.animate(alongsideTransition: { (context) in
...

let insets = ...safeAreaInsets

...
}, completion: nil)
}

关于ios - 如何在 viewWillTransitionToSize 中获取 safeAreaInsets (iPhone X),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46538117/

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