Pregunta

Actualicé a Xcode 4.2 y es una nueva función de guiones gráficos. Sin embargo, no pudo encontrar una manera de apoyar tanto el retrato como el paisaje.

Por supuesto, lo hice programáticamente, con 2 vistas, una para retrato y otra para paisaje, como en los viejos tiempos, y:

if (interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight) 
    {
        self.view = self.landscapeView;
    }
    else
    {
        self.view = self.portraitView;
    }

Pero estaba buscando una manera de hacer esto automáticamente de alguna manera. Quiero decir, es Xcode 4.2 ahora, esperaba más de él. Gracias a todos.

==================================
SOLUCIÓN TEMPORAL:

Presentaré aquí una solución temporal. Digo que es temporal, porque todavía estoy esperando que los chicos de Apple hagan algo realmente inteligente al respecto.

Creé otro archivo .StoryBoard, llamado "MainstoryBoard_iphone_LANDSCAPE" e implementé los controladores de vista al panorama allí. En realidad, es exactamente como lo normal (retrato). Storyboard, pero todas las pantallas están en modo paisajista.

Por lo tanto, extraeré el ViewController del guión gráfico del paisaje, y cuando ocurra la rotación, simplemente cambie la vista.

1. Notificaciones generadas Cuando cambia la orientación:

[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];

2. Ploque para las notificaciones:

[[NSNotificationCenter defaultCenter] addObserverForName:UIDeviceOrientationDidChangeNotification object:nil queue:nil usingBlock:^(NSNotification *note) {    
    // We must add a delay here, otherwise we'll swap in the new view  
    // too quickly and we'll get an animation glitch  
    [self performSelector:@selector(updateLandscapeView) withObject:nil afterDelay:0];
}];

3. Implemento Updatelandscapeview

- (void)updateLandscapeView {  
 //>     isShowingLandscapeView is declared in AppDelegate, so you won't need to declare it in each ViewController
 UIDeviceOrientation deviceOrientation       = [UIDevice currentDevice].orientation;
 if (UIDeviceOrientationIsLandscape(deviceOrientation) && !appDelegate().isShowingLandscapeView)
 {
     UIStoryboard *storyboard                = [UIStoryboard storyboardWithName:@"MainStoryboard_iPhone_Landscape" bundle:[NSBundle mainBundle]];
     MDBLogin *loginVC_landscape             =  [storyboard instantiateViewControllerWithIdentifier:@"MDBLogin"];
     appDelegate().isShowingLandscapeView    = YES;  
     [UIView transitionWithView:loginVC_landscape.view duration:0 options:UIViewAnimationOptionTransitionCrossDissolve|UIViewAnimationCurveEaseIn animations:^{
         //>     Setup self.view to be the landscape view
         self.view = loginVC_landscape.view;
     } completion:NULL];
 }
 else if (UIDeviceOrientationIsPortrait(deviceOrientation) && appDelegate().isShowingLandscapeView)
 {
     UIStoryboard *storyboard                = [UIStoryboard storyboardWithName:@"MainStoryboard_iPhone" bundle:[NSBundle mainBundle]];
     MDBLogin *loginVC                       = [storyboard instantiateViewControllerWithIdentifier:@"MDBLogin"];
     appDelegate().isShowingLandscapeView    = NO;
     [UIView transitionWithView:loginVC.view duration:0 options:UIViewAnimationOptionTransitionCrossDissolve|UIViewAnimationCurveEaseIn animations:^{
         //>     Setup self.view to be now the previous portrait view
         self.view = loginVC.view;
     } completion:NULL];
 }}

Buena suerte a todos.

PD: Aceptaré la respuesta de Ad Taylor, porque, después de mucho tiempo esperando y buscando una solución, terminé implementando algo inspirado en su respuesta. Gracias Taylor.

¿Fue útil?

Solución

Esta es una vieja pregunta, pero leí esto más temprano en el día y luego tuve que pasar una buena cantidad de tiempo para el ejercicio de una mejor solución. Se me ocurrió esta solución al piratear el Ejemplo de vista alternativa de Apple. Básicamente está sirviendo una vista modal para la vista del paisaje.

#pragma mark Rotation view control

- (void)orientationChanged:(NSNotification *)notification
{
    // We must add a delay here, otherwise we'll swap in the new view
    // too quickly and we'll get an animation glitch
    [self performSelector:@selector(updateLandscapeView) withObject:nil afterDelay:0];
}

- (void)updateLandscapeView
{
    UIDeviceOrientation deviceOrientation = [UIDevice currentDevice].orientation;
    if (UIDeviceOrientationIsLandscape(deviceOrientation) && !self.isShowingLandscapeView)
    {
        [self performSegueWithIdentifier: @"toLandscape" sender: self];
        self.isShowingLandscapeView = YES;
    }
    else if (deviceOrientation == UIDeviceOrientationPortrait && self.isShowingLandscapeView)
    {
        [self dismissModalViewControllerAnimated:YES];
        self.isShowingLandscapeView = NO;
    }    
}


- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

Otros consejos

En general, no debe pensar en puntos de vista separados para diferentes orientaciones a menos que sean ampliamente diferentes (lo que, posiblemente, no deberían serlo). En cambio, debes confiar en Máscaras de autoresización Para diseñar tanto el contenido de su vista en función de las restricciones básicas cuando cambia el marco de la supervisión. Esto permitirá que las subvistas respondan adecuadamente a un cambio en el marco de su supervisión, a menudo como resultado de un cambio de orientación de interfaz.

Para responder a su pregunta más directamente, no, no hay forma de que Xcode asuma o se le diga qué vistas desea usar para una orientación de interfaz particular, ya que esta nunca fue la intención de UIKit'S View Architecture.

Aquí hay más información sobre cómo autorizar máscaras: Manejo de cambios de diseño automáticamente utilizando reglas de autoresización.

En Xcode v4.2.1, cuando usa guiones gráficos, solo puede cambiar la orientación del controlador de vista, y no la vista en sí, por lo que si ha insertado otra vista allí, no podría cambiar su orientación, incluso si pudiera ver el Ver correctamente.

Por lo tanto, la forma anterior de tener dos vistas no parecería funcionar al usar guiones gráficos (cuando se usa NIB donde la orientación de la vista es cambiante para vistas separadas).

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