【问题标题】:How to use requestGeometryUpdateWithPreferences in Objective C如何在 Objective C 中使用 requestGeometryUpdateWithPreferences
【发布时间】:2022-12-03 07:36:48
【问题描述】:
我有一个 Swift 语言的例子:
guard let windowScene = view.window?.windowScene else { return }
windowScene.requestGeometryUpdate(.iOS(interfaceOrientations: .portrait)) { error in }
我不能在 Objective C 中写它:
UIWindowScene *windowScene = self.view.window.windowScene;
[windowScene requestGeometryUpdateWithPreferences: UIInterfaceOrientationMaskPortrait errorHandler:nil];
请告诉我如何正确书写,如有任何帮助,我将不胜感激。
【问题讨论】:
标签:
objective-c
uiinterfaceorientation
uiwindowscene
【解决方案1】:
在 Objective-C 中编写 Swift 代码的一种方法是:
UIWindowScene *windowScene = self.view.window.windowScene;
if (!windowScene) { return; }
UIWindowSceneGeometryPreferences *preferences = [[UIWindowSceneGeometryPreferencesIOS alloc] initWithInterfaceOrientations:UIInterfaceOrientationMaskPortrait];
[windowScene requestGeometryUpdateWithPreferences:preferences errorHandler:^(NSError * _Nonnull error) {
// Handle error here
}];