我正在尝试更新iPhoneX的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()
}发布于 2017-10-05 09:09:39
我在日本斯塔克沃夫找到了有效的解决方案。
它只是获得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)
}发布于 2019-02-08 00:42:54
我也有这个问题。在实验之后,我找到了一个很好的解决办法,而不用等待过渡完成。
SizeListenerView),这样我们只需要听这个视图的大小变化在SizeListenerView中
override var bounds: CGRect {
didSet {
// now you can access the bounds here
}
}https://stackoverflow.com/questions/46538117
复制相似问题