有沒有簡單的方法來手動設置界面方向?我需要將界面設置爲縱向,即使裝載期間設備方向可能處於橫向。有點想遠離CGAffineTransforms。手動設置界面方向
Q
手動設置界面方向
4
A
回答
16
一種方法,我知道這對我的作品(並且是一個黑客位,並可以改變到你想要的方向之前顯示一個方向)是:
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
UIApplication* application = [UIApplication sharedApplication];
if (application.statusBarOrientation != UIInterfaceOrientationPortrait)
{
UIViewController *c = [[UIViewController alloc]init];
[self presentModalViewController:c animated:NO];
[self dismissModalViewControllerAnimated:NO];
[c release];
}
}
2
覆蓋它來控制方向,直到裝...
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
+0
方向屬性爲只讀 –
+0
是的,您是對的。我的錯。我更新了我的答案。您可以考慮重寫shouldAutorotateToInterfaceOrientation並根據需要維護方向。 – Saran
2
首先,設置你的應用程序和觀點,只支持人像,然後使用從我的重構庫中提取的這一類方法,es_ios_utils:
@interface UIViewController(ESUtils)
// Forces without using a private api.
-(void)forcePortrait;
@end
@implementation UIViewController(ESUtils)
-(void)forcePortrait
{
//force portrait orientation without private methods.
UIViewController *c = [[UIViewController alloc] init];
[self presentModalViewController:c animated:NO];
[self dismissModalViewControllerAnimated:NO];
[c release];
}
@end
該視圖在幀完成前關閉,將不會顯示。
相關問題
- 1. 界面方向不會自動更改
- 2. 在iPhone專用API上設置界面方向
- 3. 如何檢測設備方向與界面方向不同?
- 4. 手動設置UIPopover箭頭的方向和位置
- 5. iOS6中的界面方向
- 6. iPhone - 界面方向顛倒?
- 7. UI界面方向問題
- 8. 手動設置UUID
- 9. 手動設置AlternateItemTemplate
- 10. 手動設置ID
- 11. 手動設置livewallpaper
- 12. 手動設置r_creation_date?
- 13. 獲取手機移動方向,不論手機正面
- 14. 手動更新用戶界面
- 15. 想要使用多個筆尖來設置不同的iphone界面方向
- 16. 搖動手機方向
- 17. Iphone:手動更改方向
- 18. 如何動態設置StackPanel的方向?
- 19. UIViewController的動畫設置錯誤方向
- 20. 如何響應界面方向更改?
- 21. UIView可以「忽略」界面方向嗎?
- 22. UIToolBar和iPhone界面方向問題
- 23. 標籤欄界面方向問題
- 24. 全屏MPMoviePlayerController界面方向更改
- 25. 面向對方的特徵邊界
- 26. 在一個方向上爲邊界內的對象設置動畫
- 27. java界面 - 面向對象
- 28. iPad在啓動時無法識別正確的界面方向?
- 29. 使用OpenGL自定義iOS界面方向更改動畫
- 30. 如何手動設置UITableViewCell?
這實際上對我描述的情況非常有效。但由於某些原因,不適合嘗試從縱向模式強制橫向(將UIInterfaceOrientationPortrait更改爲UIInterfaceOrientationLandscapeLeft)。想法? –
實際工作的骯髒的黑客。 – beefon
謝謝!偉大的代碼行=) – CReaTuS