我有2個視圖控制器A和B.視圖控制器A僅爲縱向,視圖控制器B可以旋轉。使視圖控制器根據設備方向立即旋轉
當手機是風景時,我推視圖控制器A,它的方向是肖像 - >好。
但是當我從視圖控制器A(手機仍然是風景)推視圖控制器B時,視圖控制器B的方向是肖像,這不是我想要的。 我必須將設備旋轉到縱向然後橫向使視圖控制器B旋轉到橫向。
我的問題是,我如何使視圖控制器B在從A推入後立即旋轉,關於設備方向?
我有2個視圖控制器A和B.視圖控制器A僅爲縱向,視圖控制器B可以旋轉。使視圖控制器根據設備方向立即旋轉
當手機是風景時,我推視圖控制器A,它的方向是肖像 - >好。
但是當我從視圖控制器A(手機仍然是風景)推視圖控制器B時,視圖控制器B的方向是肖像,這不是我想要的。 我必須將設備旋轉到縱向然後橫向使視圖控制器B旋轉到橫向。
我的問題是,我如何使視圖控制器B在從A推入後立即旋轉,關於設備方向?
使用此可以解決您的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;
}
要在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
對不起,什麼是restrictRotation? – Tien