簡體   English   中英

iOS 8鎖定方向

[英]iOS 8 Lock Orientation

我繼承了一個在iOS 6之前構建的iOS應用程序。到目前為止,它在iOS 8中不起作用。我的目標是讓當前應用程序在iOS 8中保持其當前狀態,然后編寫該應用程序的全新版本將其帶入現代時代。

我是一個Objective-C新手,所以我正在逐步解決每個修復問題。 該應用程序當前狀態下的主要問題是主視圖控制器在打開時處於縱向狀態。 整個應用程序應被鎖定為橫向正確,但是當您打開時,它以縱向開始。 如果單擊主頁並重新打開該應用程序,則該應用程序處於橫向狀態。

在Info.plist中,橫向權限是唯一受支持的方向。 我還使用以下代碼將視圖控制器鎖定為橫向:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}

-(BOOL)shouldAutorotate{
    return YES;
}

-(NSUInteger)supportedInterfaceOrientations{
    return UIInterfaceOrientationMaskLandscapeRight;
}

但是,這些修復都沒有使視圖控制器可以橫向打開。

關於如何使視圖控制器在橫向上正確打開的任何想法?

該應用程序太舊了,它沒有UINavigationController設置。 設置方向是否有必要? 任何幫助或提示,不勝感激。

編輯:這是我的info.plist文件:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>CFBundleDevelopmentRegion</key>
    <string>English</string>
    <key>CFBundleDisplayName</key>
    <string>${PRODUCT_NAME}</string>
    <key>CFBundleExecutable</key>
    <string>VersePack</string>
    <key>CFBundleIconFile</key>
    <string>Icon.png</string>
    <key>CFBundleIdentifier</key>
    <string>com.TiBrew.versePack</string>
    <key>CFBundleInfoDictionaryVersion</key>
    <string>6.0</string>
    <key>CFBundleName</key>
    <string>${PRODUCT_NAME}</string>
    <key>CFBundlePackageType</key>
    <string>APPL</string>
    <key>CFBundleSignature</key>
    <string>????</string>
    <key>CFBundleVersion</key>
    <string>1.2.0</string>
    <key>LSRequiresIPhoneOS</key>
    <true/>
    <key>NSMainNibFile</key>
    <string>MainWindow</string>
    <key>NSMainNibFile~ipad</key>
    <string>MainWindow-iPad</string>
    <key>UIInterfaceOrientation</key>
    <string>UIInterfaceOrientationLandscapeRight</string>
    <key>UIStatusBarHidden</key>
    <false/>
    <key>UISupportedInterfaceOrientations</key>
    <array>
        <string>UIInterfaceOrientationLandscapeRight</string>
    </array>
    <key>UISupportedInterfaceOrientations~ipad</key>
    <array>
        <string>UIInterfaceOrientationLandscapeRight</string>
    </array>
    <key>UISupportedInterfaceOrientations~iphone</key>
    <array>
        <string>UIInterfaceOrientationLandscapeRight</string>
    </array>
</dict>
</plist>

您正在使用哪些設備? 人們在使用iPad時往往會對此卡住。

嘗試刪除上面的代碼,然后進入info.plist本身(“信息”標簽,不是常規的),並檢查“支持的界面方向(iPad)”和“支持的界面方向(iPhone)”每個僅包含1個項目,是“橫向(主頁按鈕右)”。

通常,只有當您希望將應用程序鎖定在不同方向上的不同方向時才使用您擁有的代碼,如果您希望整個東西都鎖定在一個方向上,則不需要它,因此也請仔細檢查代碼以確保刪除所有最后的跟蹤。

同樣,沒有設置UINavigationController也沒關系。

我回答了我自己的問題。 未打開時顯示的主視圖控制器未設置為應用程序的根視圖控制器。 我補充說:

self.window.rootViewController = myViewController;

到我的appDelegate.m,窗口以正確的方向出現。

暫無
暫無

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

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