16 votes

Les orientations prises en charge n'ont pas d'orientation commune avec l'application et la réponse de shouldAutorotate est OUI.

* Ma vue est en mode paysage, j'enregistre l'image et je veux la récupérer pour cela, mon code est le suivant et j'obtiens l'erreur "Terminating app due to uncaught exception 'UIApplicationInvalidInterfaceOrientation', reason : 'Supported orientations has no common orientation with the application, and shouldAutorotate is returning YES'". * que puis-je faire pour l'iphone ?

        `- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {

         [self dismissModalViewControllerAnimated:YES];
         [picker release];

              }
             - (void)imagePickerController:(UIImagePickerController *)picker 

                didFinishPickingMediaWithInfo:(NSDictionary *)info {

            [picker dismissModalViewControllerAnimated:NO];

                imageDoodle.image = [info objectForKey:@"UIImagePickerControllerMediaMetadata"];

                 }

               -(IBAction)loadfromalbumclicked:(id)sender

                 {

                UIImagePickerController * picker = [[UIImagePickerController alloc] init];

                picker.delegate = self;

                 picker.allowsEditing=NO;

        picker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;

               // self.modalTransitionStyle=UIModalTransitionStyleFlipHorizontal;

              [self presentModalViewController:picker animated:YES];
               }

              -(IBAction)savePrint{
//Save image to iOS Photo Library

                 UIImageWriteToSavedPhotosAlbum(imageDoodle.image, nil, nil, nil);
//Create message to explain image is saved to Photos app library
                 UIAlertView *savedAlert = [[UIAlertView alloc] initWithTitle:@"Saved"  

                message:@"Your picture has been saved to the photo library, view it in the 

               Photos app." delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil];
//Display message alert
             [savedAlert show];
              }`

16voto

vshall Points 407

Essayez de définir shouldAutoRotate sur NO et voyez si cela fonctionne.

Vous pouvez utiliser les méthodes shouldAutoRotate et supportedInterfaceOrientations dans iOS 6.0 ou ultérieur, au lieu de la méthode (dépréciée) shouldAutoRotateToInterfaceOrientation.

Quelque chose comme ça -

- (NSUInteger)supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskAll;
}

- (BOOL) shouldAutorotate {
    return YES;
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
    return UIInterfaceOrientationPortrait;
}

6voto

Vino Points 3249

Vous ne supportez que des orientations limitées : paysage ou portrait. Mais vous appelez une orientation différente dans votre contrôleur de vue.

Vous pouvez voir l'image suivante avec l'orientation supportée. Il ne prend en charge que le paysage à droite et le paysage à gauche, donc si j'appelle le portrait, il affichera l'erreur comme vous. Si vous voulez supporter les deux orientations, changez-les dans le résumé.

enter image description here

Voir cette réponse pour plus de détails. J'espère que cela vous aidera.

EDIT

Vous devez donc mettre ce code dans votre viewcontroller

  - (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
  return UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskLandscapeLeft |   UIInterfaceOrientationMaskLandscapeRight;
 }

5voto

Pieter Points 9200

Cette erreur est déclenchée s'il y a une différence entre les orientations d'interface prises en charge dans la liste et celles renvoyées par la fonction -(NSUInteger)supportedInterfaceOrientations

Gardez à l'esprit que le NSUInteger retourné par le supportedInterfaceOrientations doit être une UIInterfaceOrientationMask, notez le -MASK-, j'ai fait une fois l'erreur de retourner simplement une UIInterfaceOrientation sans tenir compte de la valeur ...Mask (c'est la complétion automatique pour vous).

par exemple

- (NSUInteger) supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskPortrait;
    // and NOT UIInterfaceOrientationPortrait;
}

4voto

Prince Points 16165

Note : Si vous utilisez UIImagePickerController o UIPopoverController et ces error se produit alors la solution ci-dessous est sacrément bonne.

Ces erreurs apparaissent également dans iOS 6.0 seulement

Créez-en un nouveau UIImagePickerController's category et add

@implementation UIImagePickerController(custom)

  -(BOOL)shouldAutorotate
  {
    return NO;
  }
@end

Ça marche pour moi.

1voto

elroy Points 21

Si vous utilisez cocos2d v2.1, vous pouvez essayer ceci pour Portrait.

    -(NSUInteger)supportedInterfaceOrientations {

    // iPhone only
    if( [[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone )
        return UIInterfaceOrientationMaskPortrait;

    // iPad only
    return UIInterfaceOrientationMaskPortrait;
}

// Supported orientations. Customize it for your own needs
// Only valid on iOS 4 / 5. NOT VALID for iOS 6.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // iPhone only
    if( [[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone )
        return UIInterfaceOrientationIsPortrait(interfaceOrientation);
    // iPad only
    // iPhone only
    return UIInterfaceOrientationIsPortrait(interfaceOrientation);
}

Le site Orientations soutenues et Rotation automatique Orientations devrait être le même .

Prograide.com

Prograide est une communauté de développeurs qui cherche à élargir la connaissance de la programmation au-delà de l'anglais.
Pour cela nous avons les plus grands doutes résolus en français et vous pouvez aussi poser vos propres questions ou résoudre celles des autres.

Powered by:

X