Pregunta

He estado buscando mucho en esto, y no puedo encontrar nada que me ayude.

Tengo un UIViewController contenida dentro de otra UIViewController. Cuando gira UIViewController padres, dicen de vertical a LandscapeLeft, quiero hacer que parezca como si el niño no gire. Es decir. Quiero que el niño tenga la misma orientación hacia el cielo sin importar la orientación de los padres. Si tiene un UIButton que está en posición vertical en Retrato, quiero que el lado derecho del botón como "arriba" en UIInterfaceOrientationLandscapeLeft.

¿Es esto posible? Actualmente, estoy haciendo cosas realmente bruto como esto:

-(void) rotate:(UIInterfaceOrientation)fromOrientation: toOr:(UIInterfaceOrientation)toOrientation
{
    if(((fromOrientation == UIInterfaceOrientationPortrait) && (toOrientation == UIInterfaceOrientationLandscapeRight))
       || ((fromOrientation == UIInterfaceOrientationPortraitUpsideDown) && (toOrientation == UIInterfaceOrientationLandscapeLeft)))
    {

    }
    if(((fromOrientation == UIInterfaceOrientationLandscapeRight) && (toOrientation == UIInterfaceOrientationPortraitUpsideDown))
       || ((fromOrientation == UIInterfaceOrientationLandscapeLeft) && (toOrientation == UIInterfaceOrientationPortrait)))
    {

    }
    if(((fromOrientation == UIInterfaceOrientationPortrait) && (toOrientation == UIInterfaceOrientationLandscapeLeft))
       || ((fromOrientation == UIInterfaceOrientationPortraitUpsideDown) && (toOrientation == UIInterfaceOrientationLandscapeRight)))
    {

    }
    if(((fromOrientation == UIInterfaceOrientationLandscapeLeft) && (toOrientation == UIInterfaceOrientationPortraitUpsideDown))
       || ((fromOrientation == UIInterfaceOrientationLandscapeRight) && (toOrientation == UIInterfaceOrientationPortrait)))
    {

    }
    if(((fromOrientation == UIInterfaceOrientationPortrait) && (toOrientation == UIInterfaceOrientationPortraitUpsideDown))
       || ((fromOrientation == UIInterfaceOrientationPortraitUpsideDown) && (toOrientation == UIInterfaceOrientationPortrait)))
    {

    }
    if(((fromOrientation == UIInterfaceOrientationLandscapeLeft) && (toOrientation == UIInterfaceOrientationLandscapeRight))
       || ((fromOrientation == UIInterfaceOrientationLandscapeRight) && (toOrientation == UIInterfaceOrientationLandscapeLeft)))
    {

    }   
}

lo que parece ser un perfecto estado de residuos de código. Por otra parte, estaba planeando sobre el uso de CGAffineTransform (como citado aquí: http://www.crystalminds.nl/ ? p = 1,102 ), pero estoy confundido acerca de si debería cambiar las dimensiones de la vista para que coincida con lo que será después de la rotación.

La gran pesadilla aquí es que usted tiene que seguir la pista de una "orientación" variable global. Si no lo hace, la ilusión se pierde y el ViewController se gira en lo que sea.

Me vendría bien un poco de ayuda en esto, gracias!

¿Fue útil?

Solución

Lo mejor que puede hacer es cambiar los marcos de sus cuadros subvista acuerdo con ur orientaciones de interfaz. Puede hacerlo como:

 #pragma mark -
 #pragma mark InterfaceOrientationMethods

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    return (interfaceOrientation == UIInterfaceOrientationPortrait || interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown || interfaceOrientation == UIInterfaceOrientationLandscapeRight || interfaceOrientation == UIInterfaceOrientationLandscapeLeft);
}

//--------------------------------------------------------------------------------------------------------------------------------------------------------------------

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration{
    [super willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration];
    if(toInterfaceOrientation == UIInterfaceOrientationPortrait || toInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown){
        //self.view = portraitView;
        [self changeTheViewToPortrait:YES andDuration:duration];

    }
    else if(toInterfaceOrientation == UIInterfaceOrientationLandscapeRight || toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft){
        //self.view = landscapeView;
        [self changeTheViewToPortrait:NO andDuration:duration];
    }
}

//--------------------------------------------------------------------------------------------------------------------------------------------------------------------

- (void) changeTheViewToPortrait:(BOOL)portrait andDuration:(NSTimeInterval)duration{

    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:duration];

    if(portrait){
        //change the view and subview frames for the portrait view
    }
    else{   
        //change the view and subview  frames for the landscape view
    }

    [UIView commitAnimations];
}

Espero que esto ayude.

Otros consejos

i di cuenta de algo .. digamos que nuestro proyecto tiene múltiples capas de ViewController (como en si se agrega subvista de otro controlador de vista a su controlador de vista)

willRotateToInterfaceOrientation: Método de duración no será llamado para la segunda capa de ViewController ...

Así que lo que hice fue, después de que inicializar mi segundo controlador de vista capa de mi top mayoría de la capa, a continuación, cuando willRotateToInterfaceOrientation: Método de duración se llama en la mayoría de capa superior, que llamaré willRotateToInterfaceOrientation: duración de segundo controlador de vista de capas que así

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