肖像取向
回答
您使用的代碼取決於你的目標iOS版:
的iOS 6+
有一個叫supportedInterfaceOrientations
方法,做你在找什麼:
- (NSUInteger)supportedInterfaceOrientations
{
//If you want to support landscape
return UIInterfaceOrientationMaskAll;
//If you don't
return UIInterfaceOrientationMaskPortrait;
}
- (BOOL)shouldAutorotate {
return YES;
}
根據放每個視圖控制器中的return語句。
的iOS 5和前:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
return !(UIInterfaceOrientationIsLandscape(toInterfaceOrientation));
}
是的,謝謝它在我的模擬器上工作,我會建立它iPad和檢查,並給你的反饋 – user3202087
嘿它不是在我的主要應用程序,其中有很多viewControllers呈現在一個我想限制到肖像那裏我添加上面的代碼,但它不工作。景觀也。你有其他方式嗎? – user3202087
你寫的這個iOS版本是什麼? – David
如果您使用的是模型風險投資之間呈現,@大衛的答案是正確的。 但是,如果您使用UINavigationController
push/pop,事情會變得更加複雜。
- (NSUInteger)supportedInterfaceOrientations
和- (BOOL)shouldAutorotate
僅在設備旋轉或根控制器更改後纔會調用。推/流行將不會使它。
在iOS5中和之前,有一個API:
[[UIDevice currentDevice] setOrientation: UIInterfaceOrientationPortrait];
但它已被否決。蘋果讓它變得私密。
你仍然可以使用objc運行時API來調用它的iOS 6+,如:
objc_msgSend([UIDevice currentDevice], @selector(setOrientation:), @(UIInterfaceOrientationPortrait));
或
[[UIDevice currentDevice] setValue:@(UIInterfaceOrientationPortrait)
forKey:@"orientation"];
注意:它是私有的API,這可能是由被拒絕App Store。
另一個棘手的方式是,只提出一個空的VC然後關閉它在viewDidAppear
,是這樣的:
[self presentViewController:[UIViewController new]
animated:NO
completion:^{
[self dismissViewControllerAnimated:NO completion:nil];
}];
這將使- (NSUInteger)supportedInterfaceOrientations
和- (BOOL)shouldAutorotate
被調用。
如果您對上述不滿意。儘量讓自己的導航控制器,或 檢查出這個問題:Why can't I force landscape orientation when use UINavigationController?。
感謝它運作良好。但有一個問題,當這個視圖打開它變成肖像,但是當我將它旋轉到左邊4次時,它是第四次進入景觀。 :( – user3202087
@ user3202087我無法弄清楚爲什麼現在用你的描述,也許你可以問一個新的問題併發布代碼 – lancy
其實,我使用的是navigationController push/pop,這就是爲什麼大衛的代碼不工作,你的代碼有一個問題(上面提到的一個),但我改變了推/流行呈現viewController。總之Thanx的幫助你ppl給。:) – user3202087
- 1. Phonegap構建,啓用次肖像取向?
- 2. 肖像取向的景觀佈局android
- 3. 取向不改爲肖像,iOS遊戲
- 4. 屏幕方向 - 反向肖像
- 5. IReport結合風景和肖像方向
- 6. 強制「肖像」方向模式
- 7. 肖像圖片方向錯誤?
- 8. tabbarcontroller的肖像模式方向問題?
- 9. DOMPDF頁面方向風景和肖像
- 10. 只有景觀UIView轉向肖像
- 11. android:@ Theme.Translucent將方向鎖定爲肖像?
- 12. MPMoviePlayerController重定向肖像到風景並返回到肖像(iOS 4.1)
- 13. Android:在僅肖像應用中獲取物理設備方向
- 14. 肖像取向正在失去觸摸輸入
- 15. WPF肖像(vizualization)
- 16. 在肖像
- 17. 如何肖像
- 18. 使用opencv將肖像圖像轉換爲肖像
- 19. IOS設備方向卡住肖像模式,沒有橫向
- 20. UIImage填充肖像圖像
- 21. 1140格ipad肖像
- 22. 在肖像模式下的攝像機方向在android
- 23. 屏幕方向像iphone中的肖像和風景
- 24. JavaCV錄像機的方向不適合肖像模式
- 25. 橫向視圖不顯示圖像和肖像顯示
- 26. 從景觀只從肖像只有肖像
- 27. 如何在Android中將肖像保存爲肖像?
- 28. 3個媒體查詢iphone的肖像,風景和ipad肖像
- 29. 安卓:啓動活動總是在肖像,但承認取向變化
- 30. iPhone:從相機用戶只能採取'肖像'導向的照片
它是一個單獨的視圖控制器或只是一個UIView? – David
單獨的viewController。總而言之,我有兩個viewControllers.For第二個我想限制爲肖像。 – user3202087
SEE:http:// stackoverflow。com/questions/18595561/alternative-ios-layouts-for-portrait-and-landscape-using-just-one-xib-file –