[英]iOS 8: Autorotation is not working without storyboard
所以我試圖啟動一個沒有Storyboard的項目,我似乎無法弄清楚為什么UIWindow沒有將自動旋轉命令傳遞給根視圖控制器。 通過故事板,自動旋轉起作用。 如果我以編程方式創建窗口,則自動旋轉不起作用。
這是我在App Delegate中實例化窗口的方法:
window = UIWindow(frame: UIScreen.mainScreen().bounds)
if let window = window {
window.backgroundColor = UIColor.whiteColor()
window.makeKeyAndVisible()
let nc: SignInViewController = UIStoryboard(name: "Main", bundle: nil)
.instantiateViewControllerWithIdentifier("SignInViewController") as SignInViewController
window.rootViewController = nc
}
謝謝!
你在使用故事板嗎? 如果是這樣,您的應用程序中可能有舊代碼didFinishLaunchingWithOptions方法。
嘗試刪除以下代碼行以及與UIWindow相關的任何其他代碼:
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
只需要從AppDelegate.m文件中刪除上面的行。
標記的答案是降級到XCode 6.0.1 - 我不推薦它。
1)如果您不使用故事板 (本主題的答案!!)
轉到 - >項目名稱 - >目標 - >項目名稱 - >部署信息 - > 主界面 - >將其清空
2)萬一你使用故事板 (不是主要答案)
你的AppDelegate應該看起來像......
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool
{
return true
}
確保在項目的常規設置中啟用設備方向
在xcode 6.1中,單擊主項目文件夾,常規選項卡
向下滾動到設備方向,啟用“縱向”,“向左橫向”,“橫向右側”
有關“設備方向”設置的圖片,請參閱iOS 8.1自動旋轉
我剛剛解決了我項目中的問題。 對我來說,解決方案是從以下代碼中刪除動畫:
[self presentViewController: root animated: animated completion:^{ [AppDelegate singleton].window.rootViewController = root; }];
現在只是[AppDelegate singleton].window.rootViewController = root;
我不知道這是否能回答你的問題,但它解決了我認為是共同問題的實例。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.