He hecho una aplicación de prueba para familiarizarme con la creación de un controlador de vista de contenedor personalizado. Si giro el dispositivo cuando la aplicación se inicia por primera vez o después de cambiar a un controlador de vista diferente, la nueva vista cambia de tamaño para ocupar toda la pantalla, como pretendía. Sin embargo, si giro después de que se inicia la aplicación, y luego cambio a un nuevo controlador de vista, la vista mantiene su tamaño de retrato en lugar de acortarse y ampliarse (en realidad es ligeramente diferente: va de 320,460 a 300,480). El controlador de vista maestra se inicia con alloc en el delegado de la aplicación (no xib) y se configura como el controlador de la vista raíz de la ventana. Aquí está el código que tengo en mi MasterViewController (el controlador contenedor personalizado):Vistas Sin cambio de tamaño después de la rotación en el controlador de contenedor personalizado
- (void)viewDidLoad {
[super viewDidLoad];
WelcomeController *welcome = [[WelcomeController alloc] initWithNibName:@"ViewController" bundle:nil];
self.currentController = welcome;
[self addChildViewController:welcome];
[self.view addSubview:welcome.view];
UISwipeGestureRecognizer *swipeLeft = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeLeft:)];
swipeLeft.direction = UISwipeGestureRecognizerDirectionLeft;
[self.view addGestureRecognizer:swipeLeft];
}
- (void)swipeLeft:(UISwipeGestureRecognizer *)gesture {
if (gesture.state == UIGestureRecognizerStateRecognized) {
UIActionSheet *sheet =[[UIActionSheet alloc] initWithTitle:@"Select A Destination" delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:@"welcome",@"Play",@"Scores", nil];
[sheet showInView:self.view];
}
}
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
switch (buttonIndex) {
case 0:{
if ([self.currentController class] != [WelcomeController class]) {
WelcomeController *welcome = [[WelcomeController alloc] initWithNibName:@"ViewController" bundle:nil];
[self addChildViewController:welcome];
[self moveToNewController:welcome];
}
break;
}
case 1:{
if ([self.currentController class] != [PlayViewController class]) {
PlayViewController *player = [[PlayViewController alloc] initWithNibName:@"PlayViewController" bundle:nil];
[self addChildViewController:player];
[self moveToNewController:player];
}
break;
}
case 2:{
if ([self.currentController class] != [HighScores class]) {
HighScores *scorer = [[HighScores alloc] initWithNibName:@"HighScores" bundle:nil];
[self addChildViewController:scorer];
[self moveToNewController:scorer];
}
break;
}
case 3:
NSLog(@"Cancelled");
break;
default:
break;
}
}
-(void)moveToNewController:(id) newController {
[self.currentController willMoveToParentViewController:nil];
[self transitionFromViewController:self.currentController toViewController:newController duration:.6 options:UIViewAnimationOptionTransitionCrossDissolve animations:^{}
completion:^(BOOL finished) {
[self.currentController removeFromParentViewController];
[newController didMoveToParentViewController:self];
self.currentController = newController;
}];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return YES;//(interfaceOrientation == (UIInterfaceOrientationPortrait | UIInterfaceOrientationLandscapeLeft));
}
Cualquier idea por qué esto está ocurriendo (no sé si esto significa que la opinión del controlador de vista maestro no se cambio de tamaño, pero Cuando obtengo este comportamiento sin cambio de tamaño, el reconocedor de gestos solo responde en la vista estrecha, no en toda la pantalla.
Descubrí que si uso un archivo xib y alloc initWithNibName: paquete: en lugar de solo init, funciona correctamente. Entonces, parece tener algo que ver con la vista que obtienes cuando simplemente inicias. Sin embargo, cuando registro la vista, tiene el mismo aspecto ya sea desde el archivo plain init o el archivo xib: ambos tienen el mismo marco y el mismo autoresize = W + H – rdelmar
define autoresizingMask programmatically 'UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight' – yasirmturk