Ios7 在ios 7中返回到上一个视图控制器时,只有一个视图控制器方向问题
在我的应用程序中,我们只需要一个视图控制器将处于所有方向模式,其他视图控制器将仅处于纵向模式 我使用下面的代码,它的工作非常完美,但当回到pervious view controller时,当我从横向模式返回时,它不会在纵向模式下旋转Ios7 在ios 7中返回到上一个视图控制器时,只有一个视图控制器方向问题,ios7,orientation,Ios7,Orientation,在我的应用程序中,我们只需要一个视图控制器将处于所有方向模式,其他视图控制器将仅处于纵向模式 我使用下面的代码,它的工作非常完美,但当回到pervious view controller时,当我从横向模式返回时,它不会在纵向模式下旋转 - (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window { // Get topmost
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {
// Get topmost/visible view controller
UIViewController *currentViewController = [self topViewController];
// Check whether it implements a dummy methods called canRotate
if ([currentViewController respondsToSelector:@selector(canRotate)]) {
// Unlock landscape view orientations for this view controller
return UIInterfaceOrientationMaskAllButUpsideDown;
}
// Only allow portrait (standard behaviour)
return UIInterfaceOrientationMaskPortrait;
}
- (UIViewController*)topViewController {
return [self topViewControllerWithRootViewController:[UIApplication sharedApplication].keyWindow.rootViewController];
}
- (UIViewController*)topViewControllerWithRootViewController:(UIViewController*)rootViewController {
if ([rootViewController isKindOfClass:[UITabBarController class]]) {
UITabBarController* tabBarController = (UITabBarController*)rootViewController;
return [self topViewControllerWithRootViewController:tabBarController.selectedViewController];
} else if ([rootViewController isKindOfClass:[UINavigationController class]]) {
UINavigationController* navigationController = (UINavigationController*)rootViewController;
return [self topViewControllerWithRootViewController:navigationController.visibleViewController];
} else if (rootViewController.presentedViewController) {
UIViewController* presentedViewController = rootViewController.presentedViewController;
return [self topViewControllerWithRootViewController:presentedViewController];
} else {
return rootViewController;
}
}
我一直在反对同一个问题。通过在要返回的控制器的视图中添加调整,可以强制将方向恢复到其正常配置:
-(void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
NSNumber *value = [NSNumber numberWithInt:UIInterfaceOrientationPortrait];
[[UIDevice currentDevice] setValue:value forKey:@"orientation"];
}