¿Cuáles son algunas de las posibles causas de un UIView raramente no estar giradas cuando revisited?

StackOverflow https://stackoverflow.com/questions/1236728

Pregunta

Pongo este código en todos mis 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;
    }   

y también tengo:

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

    return (interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}

Puedo ver que los códigos funcionen correctamente como debe ser, pero de vez en cuando, hay una rara ocasión que el principal controlador de vista no pudo girar para el modo paisaje después de poner su vista de nuevo a la vista principal. La posibilidad de que se produce es muy raro, pero esto me está molestando. Por otra parte, puedo ver que ocurre con más frecuencia en el iPhone. En el simulador, recordé que nunca suceda. ¿Sabe lo que son las posibles causas de esto? Gracias de antemano.

¿Fue útil?

Solución

He encontrado la causa de mi programa de iPhone.

Una de las posibles causas es la memoria. Este método a continuación se llamará cuando el sistema está bajo de memoria:

- (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.
}

Una UIView "invisible" se descarga cuando se llama a este método. Cuando están a punto de ver de nuevo este punto de vista, el dispositivo vuelve a cargar, pero tal vez porque se establecen los parámetros (para la rotación, etc.) en un lugar donde no se llama cuando se vuelve a cargar. Usted puede 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];
}

Se produce en el dispositivo debido a que estamos hablando de memoria real en el dispositivo real. Puede utilizar "Hardware> Simular Advertencia de memoria" cuando se utiliza el simulador.

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