0

我有父視圖控制器和另一個模式視圖控制器。 我父母的背景下提出的模態視圖控制器:IOS視圖控制器方向

readingViewController * reading_view_controller = [[readingViewController alloc] initWithNibName:@"readingViewController" bundle:nil]; 
[self setModalPresentationStyle:UIModalPresentationCurrentContext]; 
[self presentModalViewController:reading_view_controller animated:YES]; 

家長的viewController不會東方園林;所以,我加入在父的viewController這些方法:

- (NSUInteger)supportedInterfaceOrientations{ 
    return UIInterfaceOrientationMaskPortraitUpsideDown|UIInterfaceOrientationMaskPortrait; 
} 


-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation{ 
    return (toInterfaceOrientation == UIInterfaceOrientationPortrait || toInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown); 
} 

所呈現的viewController(模態呈現)應定向到所有可能的方向;所以,我添加了這些方法:

- (NSUInteger)supportedInterfaceOrientations{ 
    return UIInterfaceOrientationMaskAll; 
} 

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation{ 

    return YES; 
} 

但是,因爲我認爲(UIModalPresentationCurrentContext),所提出的viewController不IOS 6.0,而它正在爲IOS 5.0預計

如何解決這個定位問題請問?

回答

0

你應該實現

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation; 

如: -

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation 
{ 
    return UIInterfaceOrientationMaskAll; 
} 
+0

 @implementation UITabBarController (SK8FASTR2App) -(BOOL)shouldAutorotate { return YES; } - (NSUInteger)supportedInterfaceOrientations { // your custom logic for rotation of selected tab if (self.selectedIndex==3){ return UIInterfaceOrientationMaskPortrait; } else { UIInterfaceOrientationMaskPortrait|UIInterfaceOrientationMaskPortraitUpsideDown|UIInterfaceOrientationLandscapeLeft|UIInterfaceOrientationLandscapeRight; return UIInterfaceOrientationMaskAll; } } @end before @implementation AppDelegate - (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window { return UIInterfaceOrientationMaskAll; } 

改變方向,我實現它,但沒有改變 – yasserislam

+0

是在其他控制器的的viewController?我的意思是像navigationController或tabViewController。如果它在它們下面,那麼你應該繼承它們以覆蓋方向方法或創建類別來覆蓋它們。這應該使它工作。 –

1

如果你有一個基於選項卡的應用程序,然後在第一個應用程序委託添加一些代碼,也self.window.rootviewcontroller-self.tabbarcontroller。在該類

-(BOOL)shouldAutorotate 
{ 
    return NO; 
} 

-(NSUInteger)supportedInterfaceOrientations 
{ 
    return UIInterfaceOrientationMaskLandscapeRight; 
} 

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation 
{ 
    return UIInterfaceOrientationLandscapeRight; 
}