Pergunta

Eu coloquei este código em todas as minhas viewControllers:

    UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];

    if (orientation == UIInterfaceOrientationLandscapeRight) {
        CGAffineTransform transform = self.view.transform;

        // Use the status bar frame to determine the center point of the window's content area.
        //CGRect statusBarFrame = [[UIApplication sharedApplication] statusBarFrame];
        //CGRect bounds = CGRectMake(0, 0, statusBarFrame.size.height, statusBarFrame.origin.x);
        CGPoint center = CGPointMake(320/2, 480/2);

        // Set the center point of the view to the center point of the window's content area.
        self.view.center = center;

        // Rotate the view 90 degrees around its new center point.
        transform = CGAffineTransformRotate(transform, (M_PI / 2.0));
        self.view.transform = transform;
    }   

e também tenho:

 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations

    return (interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}

Eu posso ver que os códigos de funcionar corretamente como deveriam, mas de vez em quando, há uma rara ocasião em que o principal controlador de vista não conseguiu girar para o modo paisagem depois de eu colocar seu ponto de vista de volta para ser a vista principal. A chance de que ela ocorre é muito raro, mas isso está me incomodando. Além disso, eu posso ver que ela ocorre com mais frequência no iPhone. No simulador, lembrei-me que nunca acontecer. Sabe quais são as possíveis causas para isso? Agradecemos antecipadamente.

Foi útil?

Solução

Eu encontrei a causa do meu programa de iphone.

Uma das possíveis causas é a memória. Este método abaixo será chamado quando o sistema está com pouca memória:

- (void)didReceiveMemoryWarning {
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];

    // Release any cached data, images, etc that aren't in use.
}

Um "invisível" UIView é descarregado quando este método é chamado. Quando você está prestes a ver este ponto de vista novamente, o dispositivo recarregado-lo, mas talvez porque você definir os parâmetros (para a rotação, etc.) em um lugar onde ele não será chamado quando ele é recarregado. Você pode usar:

- (void)viewDidLoad {

    UIApplication* application = [UIApplication sharedApplication];
    application.statusBarOrientation = UIInterfaceOrientationLandscapeRight;

    CGAffineTransform landscapeTransform = CGAffineTransformMakeRotation([MyMath radd:90]);
    landscapeTransform = CGAffineTransformTranslate (landscapeTransform, -80, 83);

    [self.view setTransform: landscapeTransform];
    [super viewDidLoad];
}

Ela ocorre no dispositivo por causa do que estamos a falar memória real no dispositivo real. Você pode usar "Hardware> Aviso Simulate memória" quando você estiver usando o simulador.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top