Pregunta

Este es un tema muy importante rotación automática y fácil de reproducir.

Mi aplicación tiene un UITabBarController. Cada pestaña es un UINavigationController. rotación automática se maneja con las llamadas normales a shouldAutorotateToInterfaceOrientation y didRotateFromInterfaceOrientation.

gira la interfaz normalmente hasta que llaman UIViewController.popViewControllerAnimated y el cambio UITabBarController.selectedIndex.

Pasos para reproducir:

  1. Crear una demo Tab barra de aplicaciones.
  2. Agregue el código siguiente al archivo de la aplicación Delegado .h:
    #import <UIKit/UIKit.h>
    @interface TestRotationAppDelegate : NSObject { UIWindow *window; UITabBarController *tabBarController; }
    @property (nonatomic, retain) IBOutlet UIWindow *window; @property (nonatomic, retain) IBOutlet UITabBarController *tabBarController;
    @end
    // Redefine the interface to cach rotation messages @interface UITabBarController (TestRotation1AppDelegate)
    @end
  3. Agregue el código siguiente al archivo de la aplicación Delegado .m:
    #import "TestRotationAppDelegate.h"
    @implementation TestRotationAppDelegate @synthesize window; @synthesize tabBarController;
    -(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { [window addSubview:tabBarController.view]; [window makeKeyAndVisible]; return YES; }
    -(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { return YES; }
    -(void)dealloc { [tabBarController release]; [window release]; [super dealloc]; }
    @end
    @implementation UITabBarController (TestRotation1AppDelegate)
    -(void)viewDidLoad { [super viewDidLoad]; // Add a third tab and push a view UIViewController *view1 = [[[UIViewController alloc] init] autorelease]; view1.title = @"Third"; UINavigationController *nav = [[[UINavigationController alloc] initWithRootViewController:view1] autorelease]; NSMutableArray *array = [[NSMutableArray alloc] init]; [array addObjectsFromArray:self.viewControllers]; [array addObject:nav]; self.viewControllers = array; // Push view2 inside the third tab UIViewController *view2 = [[[UIViewController alloc] init] autorelease]; [nav pushViewController:view2 animated:YES]; // Create a button to pop view2 UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect]; button.frame = CGRectMake(50, 50, 220, 38); [button setTitle:@"Pop this view" forState:UIControlStateNormal]; [button addTarget:self action:@selector(doAction) forControlEvents:UIControlEventTouchUpInside]; [view2.view addSubview:button]; }
    -(void) doAction { // ROTATION PROBLEM BEGINS HERE // Remove one line of code and the problem doesn't occur. [self.selectedViewController popViewControllerAnimated:YES]; self.selectedIndex = 0; }
    -(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { return YES; }
    @end

La interfaz de automóviles gira normalmente hasta que toque en el botón de la pestaña # 3.

Su ayuda será apreciada geatly!

¿Fue útil?

Solución

iPhone SDK 3.2 resuelve este problema.

Con el uso del SDK anterior [self.selectedViewController popViewControllerAnimated: NO].

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top