2015-09-02 46 views
0

我有2个视图控制器A和B.视图控制器A仅为纵向,视图控制器B可以旋转。使视图控制器根据设备方向立即旋转

当手机是风景时,我推视图控制器A,它的方向是肖像 - >好。

但是当我从视图控制器A(手机仍然是风景)推视图控制器B时,视图控制器B的方向是肖像,这不是我想要的。 我必须将设备旋转到纵向然后横向使视图控制器B旋转到横向。

我的问题是,我如何使视图控制器B在从A推入后立即旋转,关于设备方向?

回答

1

使用此可以解决您的poblem

AppDelegate.m

-(NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window 
{ 

return UIInterfaceOrientationMaskLandscape; 

} 

的ViewController

-(void) restrictRotation:(BOOL) restriction 
{ 
AppDelegate* appDelegate = (AppDelegate*)[UIApplication sharedApplication].delegate; 
appDelegate.restrictRotation = restriction; 
} 
+0

对不起,什么是restrictRotation? – Tien

0

要在viewWillAppear中旋转设备的方向使用此代码viewWillDisAppear根据需要

NSNumber *value = [NSNumber numberWithInt:UIInterfaceOrientationPortrait]; 
[[UIDevice currentDevice] setValue:value forKey:@"orientation"]; 

并旋转查看使用此代码

[self shouldAutorotate]; 
[self supportedInterfaceOrientations]; 

而且在定义这个方法ViewController.m

-(BOOL)shouldAutorotate{ 
return YES; 
} 

- (NSUInteger)supportedInterfaceOrientations {

return UIInterfaceOrientationMaskPortrait;  
} 

它会帮助你.Thankyou