66t*_*tom 6 ios swift iphone-x
我正在尝试更新viewWillTransition(to size: with coordinator:)iPhoneX 的方法.但是我无法获得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()
}
Run Code Online (Sandbox Code Playgroud)
66t*_*tom 16
我在Stackoverflow Japan获得了有效的解决方案.
它只是在UIViewControllerTransitionCoordinator.animate(alongsideTransition:completion:)闭包中获得插件如下:
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)
}
Run Code Online (Sandbox Code Playgroud)