Question

Mon application iPhone est basé sur la navigation et contient beaucoup de pages vues portrait seulement et un paysage seule vue pour l'affichage des images. Je voudrais donc forcer ce point de vue du paysage que pour faire tourner automatiquement PAYSAGE même si l'appareil est placé en mode portrait.

Voici donc ce que I'w fait dans le contrôleur de ce point de vue:

// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationLandscapeRight); 
}

- (void)viewWillAppear:(BOOL)animated
{
 [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleBlackTranslucent animated:YES];
 [self.navigationController.navigationBar setBarStyle:UIBarStyleBlackTranslucent];

 AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];

 _originalTransform = [[appDelegate navigationController].view transform];
 _originalBounds = [[appDelegate navigationController].view bounds];
 _originalCenter = [[appDelegate navigationController].view center];

 CGAffineTransform landscapeTransform = CGAffineTransformMakeRotation(degreesToRadian(90));
 landscapeTransform = CGAffineTransformTranslate (landscapeTransform, +80.0, +100.0);

 [[appDelegate navigationController].view setTransform:landscapeTransform];

 [appDelegate navigationController].view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
 [appDelegate navigationController].view.bounds  = CGRectMake(0.0, 0.0, 480.0, 320.0);
 [appDelegate navigationController].view.center  = CGPointMake (240.0, 160.0);

 [UIApplication sharedApplication].statusBarOrientation = UIInterfaceOrientationLandscapeRight;
 }
}

- (void)viewWillDisappear:(BOOL)animated
{ 
 [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault animated:YES];
 [self.navigationController.navigationBar setBarStyle:UIBarStyleDefault];

 AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
 [[appDelegate navigationController].view setTransform:_originalTransform];
 [[appDelegate navigationController].view setBounds:_originalBounds];
 [[appDelegate navigationController].view setCenter:_originalCenter];

 [UIApplication sharedApplication].statusBarOrientation = UIInterfaceOrientationPortrait; 
}

Maintenant, j'ai toujours ce point de vue affichée en mode lanscape. Mais il y a un problème. Ce point de vue est mal positionné comme indiqué dans cette capture d'écran .

J'ai essayé de régler manuellement le cadre après la rotation, mais il n'a pas aidé. Aussi je n'ai pas trouvé un guide complet comment définir un point de vue d'être paysage uniquement. S'il vous plaît aidez-moi à ce problème.

Était-ce utile?

La solution

Consultez ce gars poste . Fondamentalement, vous devez transformer autour du centre de la fenêtre. On dirait que vous devrez peut-être tourner la barre d'état.

Une autre méthode serait d'utiliser UIDevice setDeviceOrientation, mais c'est une API privée et donc pas une bonne solution.

Autres conseils

Essayez d'utiliser cette méthode après avoir appliqué la transformation:

[self.view sizeToFit];
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top