我NotificationCenter
用来观察interfaceOrientation
变化UIApplication.willChangeStatusBarOrientationNotification
。但UIApplication.willChangeStatusBarOrientationNotification
现在标记为已弃用。建议使用viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id <UIViewControllerTransitionCoordinator>)coordinator
,但这是从 中调用的方法ViewController
。我有一个UIView
内部需要它的子类,我将它暴露View
为framework
. 我希望能够仍然保持此功能,而无需从ViewController
. 是否有另一种选择可以直接在内部实现这一目标View
?我尝试UIWindowScene.interfaceOrientation
使用 KVO 进行观察,但这不起作用。
public extension Notification.Name {
static let willChangeStatusBarOrientationNotification = UIApplication.willChangeStatusBarOrientationNotification
}
...
@objc private func statusBarOrientationWillChange(notification: Notification) {
if let orientationRawValue = notification.userInfo?[UIApplication.statusBarOrientationUserInfoKey] as? Int, let orientation = AVCaptureVideoOrientation(rawValue: orientationRawValue) {
configureVideoOrientation(interfaceOrientation: orientation)
updateSceneInformation()
}
}
...
private func initialize() {
NotificationCenter.default.addObserver(self, selector: #selector(statusBarOrientationWillChange(notification:)), name: .willChangeStatusBarOrientationNotification, object: nil)
}