Domanda

Ho cercato molto su questo, e non riesco a trovare nulla che mi aiuti.

Ho un UIViewController contenuta all'interno di un altro UIViewController. Quando la rotazione UIViewController genitore, dicono da Verticale a LandscapeLeft, voglio far sembrare come se il bambino non ruotasse. Vale a dire. Voglio che il bambino ad avere lo stesso orientamento verso il cielo indipendentemente dall'orientamento del genitore. Se ha un UIButton che è in posizione verticale in Ritratto, voglio che il lato destro del pulsante di essere "up" in UIInterfaceOrientationLandscapeLeft.

È possibile? Attualmente, sto facendo cose davvero indecente in questo modo:

-(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)))
    {

    }   
}

che sembra come una perfetta buona spreco di codice. Inoltre, stavo pensando di usare CGAffineTransform (come citato qui: http://www.crystalminds.nl/ ? p = 1102 ), ma sono confuso circa se dovrei cambiare le dimensioni della vista per corrispondere a ciò che sarà dopo la rotazione.

Il grande incubo è qui che si deve tenere traccia di una variabile globale "orientamento". Se non lo fai, l'illusione si perde e l'ViewController viene ruotato in qualunque.

ho potuto davvero usare un certo aiuto su questo, grazie!

È stato utile?

Soluzione

La cosa migliore che puoi fare è cambiare le cornici dei vostri telai visualizzazione secondaria in base alle ur orientamenti di interfaccia. Si può fare così:

 #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];
}

Spero che questo aiuti.

Altri suggerimenti

ho capito qualcosa .. diciamo che il nostro progetto ha strati multipli di ViewController (come in se si aggiunge visualizzazione secondaria di altri controller di vista al controller della vista)

willRotateToInterfaceOrientation: metodo di durata non sarà chiamato per il 2 ° strato di ViewController ...

Quindi quello che ho fatto è stato, dopo che ho inizializzo mio secondo controller della vista strato dalla mia cima più strati, poi quando willRotateToInterfaceOrientation: Metodo di durata viene chiamato sul livello più alto, io chiamerò willRotateToInterfaceOrientation: durata per il 2 ° controller della vista di livello come ben

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top