【问题标题】: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
    }];
    

    【讨论】:

      猜你喜欢
      • 2015-03-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-02-10
      • 2011-07-07
      • 2014-08-11
      • 1970-01-01
      相关资源
      最近更新 更多