[英]IOS 6 Orientations - Only One Viewcontroller supports Landscape & Portrait orientation - else ONLY Portrait
正如Long標題所示,我最近一直在努力與IOS 6 Orientations斗爭。 我正在開發一個僅基於iPhone的當前項目,幾乎所有的viewcontrollers都只支持縱向(默認方向)。 我有一個viewcontroller雖然我想給多個方向作為唯一的方向,獨立。 我該怎么做呢? 這是我的方法。 干杯'
在“設置”中 - 選擇除肖像底部向上以外的所有方向。
在Viewcontroller中,我想給出多個方向 - 這個代碼是嵌入式的
-(NSUInteger)supportedInterfaceOrientations { return UIInterfaceOrientationMaskAllButUpsideDown; } - (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation { return UIInterfaceOrientationPortrait; } -(BOOL)shouldAutorotate { return YES; }
對於viewcontollers的其余部分 - 支持一個方向(默認方向)portrait:
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationPortrait;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return UIInterfaceOrientationPortrait;
}
-(BOOL)shouldAutorotate
{
return YES;
}
它不起作用。 看起來似乎沒有調用方法 - 但是項目和構建只是堅持設置中的選定方向。 為什么這不起作用!!
任何幫助將深表感謝。
你可以讀到這個:
這就是我做的:
在所有viewcontrollers中:
#pragma mark Orientation handling
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait || interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown);
}
-(BOOL)shouldAutorotate
{
return YES;
}
-(NSUInteger)supportedInterfaceOrientations
{
return (UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskPortraitUpsideDown);
}
唯一的viewcontroller:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
return YES;
}
希望這可以幫助..
試試這個[[UIDevice currentDevice] setOrientation:UIInterfaceOrientationLandscapeRight];
你需要在構建階段為這個文件設置-fno-objc-arc
。
-supportedInterfaceOrientations應該返回一個掩碼,在你的情況下:
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait;
}
您需要為要以縱向顯示的視圖創建UINavigationController
子類。 從iOS 6開始,視圖控制器只查看父控制器或根控制器以進行旋轉處理, 而不是從您的描述中查看控制器本身。
在navcontroller subclass.m中:
// Older versions of iOS (deprecated) if supporting iOS < 5
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
return UIInterfaceOrientationIsPortrait(toInterfaceOrientation);
}
// >iOS6
- (BOOL)shouldAutorotate {
return YES;
}
// >iOS6
- (NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskPortrait;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.