簡體   English   中英

如何在 IOS 目標 C 中處理方向僅適用於一個屏幕並在按下時重置

[英]How to Handle Orientation in IOS Objective C only for one screen and reset when press

我是 IOS 開發的新手,我必須只為一個屏幕提供橫向和縱向,而所有其他屏幕都應該是縱向的。 我在 AppDelegate 文件中使用以下代碼並在我的屏幕中更改它。 但是當我按下后退按鈕時,前一個屏幕不會再次旋轉到縱向?

- (UIInterfaceOrientationMask)application:(UIApplication *) application
  supportedInterfaceOrientationsForWindow:(UIWindow *) window {
    if (self.allowLandscape) {
        return UIInterfaceOrientationMaskLandscapeLeft &
        UIInterfaceOrientationMaskLandscapeRight;
    }
    return UIInterfaceOrientationMaskPortrait;
}

在您只想顯示縱向的所有視圖控制器上的 viewWillAppear 中添加以下代碼。 不要忘記將設備方向標記為縱向和橫向模式。

NSNumber *value = [NSNumber numberWithInt:UIDeviceOrientationPortrait];
[[UIDevice currentDevice] setValue:value forKey:@"orientation"];

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM