尽管 iOS 版本相同,但比 iPhone 11 更新的 iOS 设备运行代码的方式不同

问题描述 投票:0回答:0

我有一个应用程序可以在物理和模拟器上完美地运行在所有 iPhone 11 及之后的 iOS / iPadOS 设备上。

然而,从 iPhone 12 和更新版本开始,他们有一个与屏幕旋转和

view.frame
方向相关的错误,即它与物理设备不同步。

完全相同的代码完美运行,并且在 iPhone 11 及更早版本上没有变化。

但是更改模拟器或在 iPhone 12 及更新版本的物理设备上运行,它就会崩溃。

所有设备都运行 iOS 15.0,部署目标是 iOS 15.0

有人能解释为什么会这样吗?在我使用 iOS 的这些年里,我从未见过像这样的特定于设备范围的问题。

self.floatingButtons?.view.frame: Optional((0.0, 0.0, 375.0, 812.0))
self.view.frame: (0.0, 0.0, 375.0, 812.0)
self.view.bounds: (0.0, 0.0, 375.0, 812.0)
UIDevice.current.orientation.rawValue: 1
self.floatingButtons?.view.frame: nil
self.view.frame: (0.0, 0.0, 375.0, 812.0)
self.view.bounds: (0.0, 0.0, 375.0, 812.0)
UIDevice.current.orientation.rawValue: 1
self.floatingButtons?.view.frame: Optional((0.0, 0.0, 375.0, 812.0))
self.view.frame: (0.0, 0.0, 375.0, 812.0)
self.view.bounds: (0.0, 0.0, 375.0, 812.0)
UIDevice.current.orientation.rawValue: 4
self.floatingButtons?.view.frame: Optional((0.0, 0.0, 375.0, 812.0))
self.view.frame: (0.0, 0.0, 375.0, 812.0)
self.view.bounds: (0.0, 0.0, 375.0, 812.0)
UIDevice.current.orientation.rawValue: 2
self.floatingButtons?.view.frame: Optional((0.0, 0.0, 375.0, 812.0))
self.view.frame: (0.0, 0.0, 812.0, 375.0)
self.view.bounds: (0.0, 0.0, 812.0, 375.0)
UIDevice.current.orientation.rawValue: 3
self.floatingButtons?.view.frame: Optional((0.0, 0.0, 812.0, 375.0))
self.view.frame: (0.0, 0.0, 812.0, 375.0)
self.view.bounds: (0.0, 0.0, 812.0, 375.0)
UIDevice.current.orientation.rawValue: 1  <- Changed to Portrait, but it **thinks** it's still in landscape! Only happens on devices newer than iPhone 11'
self.floatingButtons?.view.frame: Optional((0.0, 0.0, 812.0, 375.0))
self.view.frame: (0.0, 0.0, 812.0, 375.0)
self.view.bounds: (0.0, 0.0, 812.0, 375.0)

在这里你可以看到旋转事件的输出。 “浮动按钮”是我发现这个问题的方式——它们是排列在框架角落的按钮,这样当方向改变时,它们的布局也会改变。

如您所见,随着方向的变化,一切都完美无缺 - 浮动按钮值是“旧”方向,“self.view.frame/bounds”是新方向,在那行代码之后是'floatingButtons' 设置为与 self.view 相同。

然而,在最后一个方向上,view.frame/bounds 对于实际方向是错误的。

这永远不会发生在 iPhone 11 及更早版本上,只会发生在 iPhone 12 及更新版本的设备上。

ios orientation ipados iphone11 iphone12
© www.soinside.com 2019 - 2024. All rights reserved.