2010-07-26 5 views
0

Je suis aux prises avec ce problème. J'ai besoin d'une vue en mode portrait et en mode paysage pour mon application. Maintenant, quand je crée 2 boutons qui me montrent une vue de portrait et une vue de paysage (forcé par shouldAutorotateToInterfaceOrientation) ils se montrent très bien. Mais lorsque j'appelle les vues depuis le code de résultat d'un imagepicker, le portrait fonctionne très bien, mais la vue paysage est renvoyée comme ça. http://bit.ly/bfbobc.L'affichage de l'iPhone montre une mauvaise orientation

Donc juste le rendre clair: le nob est déjà tourné de 90 degrés, l'imageviewcontrol ne s'affiche que la moitié (la partie droite est hors écran) ... Mais l'iPhone n'est pas forcé en mode paysage ... Est-ce que quelqu'un peut m'expliquer s'il vous plaît ce qui se passe ici ou comment je peux y arriver! Toute aide est la bienvenue!

Voici comment j'appelle les vues depuis le code de résultat imagepickercontroller.

`- (void) imagePickerController: (UIImagePickerController *) vcImagePicker didFinishPickingMediaWithInfo: (NSDictionary *) info { NSLog (@ "La photo a été prise/choisi, maintenant nous avons besoin de décider quelle vue de présenter");

[vcImagePicker dismissModalViewControllerAnimated:YES]; 

UIImage *chosenPicture = [info objectForKey:@"UIImagePickerControllerOriginalImage"]; 

if (chosenPicture.size.width > chosenPicture.size.height) { 
    NSLog(@"pic is in landscape"); 

    EditLandscapeScreen *vcEditLandscapeScreen = [[EditLandscapeScreen alloc] initWithNibName:@"EditLandscapeScreen" bundle:nil]; 
    vcEditLandscapeScreen.ChosenImage = chosenPicture; 
    [self.view addSubview:vcEditLandscapeScreen.view]; 
    [vcEditLandscapeScreen release]; 
} 
else { 
    NSLog(@"pic is in portrait"); 

    EditPortraitScreen *vcEditPortraitScreen = [[EditPortraitScreen alloc] initWithNibName:@"EditPortraitScreen" bundle:nil]; 
    vcEditPortraitScreen.ChosenImage = chosenPicture; 
    [self.view addSubview:vcEditPortraitScreen.view]; 
    [vcEditPortraitScreen release]; 
} 

} `

Répondre

1

Si vous ajoutez un sous-vue à une vue que vous devez faire les changements d'orientation pour votre sous-vue vous. willRotateToInterfaceOrientation ne sera appelé pour la première viewcontroller donc si vous ajoutez subviews à un viewcontroller cela peut être un moyen acceptable pour vous:

dans votre ViewController:

- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation { 
    for (int i = 0; i < [self.viewControllers count]; i++) { 
     [[self.viewControllers objectAtIndex:i] didRotateFromInterfaceOrientation:fromInterfaceOrientation]; 
    } 
} 

en vous sous-vue ViewController:

- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation{ 
    [self adjustViewsForOrientation:self.interfaceOrientation]; 
} 

    - (void) adjustViewsForOrientation:(UIInterfaceOrientation)orientation { 
     if (orientation == UIInterfaceOrientationLandscapeLeft || orientation == UIInterfaceOrientationLandscapeRight) { 
      NSLog(@"Subview Landscape"); 
      //Do Your Landscape Changes here 
     } 
     else if (orientation == UIInterfaceOrientationPortrait || orientation == UIInterfaceOrientationPortraitUpsideDown) { 
      NSLog(@"Subview Portrait"); 
      //Do Your Portrait Changes here 
     } 
    } 

Cela peut vous amener dans la bonne direction.

+0

Je pars où vous allez, mais je veux forcer le paysage sur la sous-vue, pas seulement offrir la possibilité d'un paysage. J'ai forcé cela en utilisant 'shouldAutorotateToInterfaceOrientation' et en retournant YES pour les modes paysagers gauche et droite, mais cette chose 'forcing' ne fonctionne tout simplement pas quand j'appelle la sous-vue ... Des idées là-dessus? Merci quand même! – Martijn