11

Ich erstelle eine Anwendung, die nur im Querformat funktioniert.Wie UIImagePickerController präsentieren oder die Kamera in einer Nur-Landschaft-App öffnen?

Während sich anmelden möchte ich die Kamera öffnen oder eine UIImagePickerController präsentieren, aber die App mit dem folgenden Fehler abstürzt:

*** Terminating app due to uncaught exception 'UIApplicationInvalidInterfaceOrientation', reason: 'Supported orientations has no common orientation with the application, and [PUUIAlbumListViewController shouldAutorotate] is returning YES'

Wie kann ich ein Bild auswählen oder die Kamera in Landschaft präsentieren?

Antwort

-4

Implementieren Sie die shouldAutorotate Methode:

- (BOOL)shouldAutorotate { 
    UIInterfaceOrientation interfaceOrientation = [[UIApplication sharedApplication] statusBarOrientation]; 

    if (UIDeviceOrientationIsLandscape(interfaceOrientation)) { 
     return YES; 
    } 
    return NO; 
} 

This image shows the landscape orientation checked, you need to do the same

Fügen Sie diesen Code PUUIAlbumListViewController und alle anderen View-Controller. Stellen Sie sicher, dass Sie in Ihrem Ziel nur die Landschaft (Landschaft links und Landschaft rechts) ausgewählt haben.

+0

Ich habe nicht PUUIAlbumListViewController class.and App erstellt stürzt nach wie vor. – user1960279

+0

Fügen Sie das obige Code-Snippet in alle View-Controller ein, einschließlich PUUIAlbumListViewController. – Saif

+3

Ich glaube nicht, dass viele Leute außerhalb von Apple Zugriff auf PUUIAlbumListViewController haben, @saif –

5
I found solution, case closed. i add in my appdelegate.m: 

-(NSUInteger)application:(UIApplication *)application 
    supportedInterfaceOrientationsForWindow:(UIWindow *)window 
{ 
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) 
     return UIInterfaceOrientationMaskAll; 
    else /* iPad */ 
     return UIInterfaceOrientationMaskAllButUpsideDown; 
} 
+0

Die Lösung ist gut, aber was ich sehe, Crash ist weg, aber die App in nur einem vierten Teil des iPad Simulator nach Picker anzeigen angezeigt zu sehen. ist dieses Simulatorproblem oder etwas fehlt? –

+0

es auch im Hochformat + Querformat beide drehen ... sogar in nur Landschaft unterstützt Apps. –

+0

Warum funktioniert diese Lösung ...? Die Frage hat nichts darüber gesagt, sowohl auf dem iPad/iPhone – fatuhoku

4

Ich hatte das gleiche Problem in iOS 9, und keine der vorgeschlagenen Lösungen I (hier oder auf ähnliche Fragen auf SO) funktionierte für mich gefunden. Aber ich fand eine Lösung mit dem UIPopoverPresentationController, der in iOS 8 eingeführt wurde. Das ist, was ich mache, in einer App, die nur auf dem iPhone im Hochformat und nur auf dem iPad im Querformat ist. In meinem AppDelegate, ich habe dies:

func application(application: UIApplication, 
     supportedInterfaceOrientationsForWindow window: UIWindow?) 
     -> UIInterfaceOrientationMask { 
    if UIDevice.currentDevice().userInterfaceIdiom == .Pad { 
     return .Landscape 
    } else { 
     return .Portrait 
    } 
    } 

Dann im View-Controller, der das Foto Picker zeigen muss:

@IBAction func choosePictureFromLibrary() { 
    let imagePickerController = UIImagePickerController() 
    imagePickerController.delegate = self 

    // Set the presentation style and grab the presentation controller, 
    // which is created for you. 
    imagePickerController.modalPresentationStyle = .Popover 
    let presentationController = imagePickerController.popoverPresentationController 

    // You must set a sourceView or barButtonItem so that it can 
    // draw a "bubble" with an arrow pointing at the right thing. 
    presentationController?.sourceView = photoButton 

    self.presentViewController(imagePickerController, animated: true) {} 
    } 

Mit dem .Popover modal Präsentationsstil ein schönes, kompakten gibt (im Grunde iPhone Größe), die den Bildschirm auf dem iPad überlagert. Wenn Sie auf dem iPhone laufen, läuft es nur im Vollbildmodus wie eine normale modale Ansicht.

+0

Zusätzlich musste ich UIImagePicker (wenn im Querformat verwendet) ableiten und 'var supportedInterfaceOrientations' überschreiben, um' [.landscape, .portrait] '(iOS 10) –

4

Swift 3-Lösung, die

für iPhone und iPad arbeiten
func openGallary(_ sender:UIButton) 
    { 
     imagepicker?.delegate = self 
     imagepicker?.allowsEditing = false 
     imagepicker!.sourceType = UIImagePickerControllerSourceType.photoLibrary 
     if UIDevice.current.userInterfaceIdiom == .phone 
     { 
      self.present(imagepicker!, animated: true, completion: nil) 
     } 
     else 
     { 

      imagepicker?.modalPresentationStyle = .popover 
      let presentationController = imagepicker?.popoverPresentationController 
      // You must set a sourceView or barButtonItem so that it can 
      // draw a "bubble" with an arrow pointing at the right thing. 
      presentationController?.sourceView = sender 
      self.present(imagepicker!, animated: true) {} 
     } 
    } 
+1

zurückzugeben. Vielen Dank dafür! – LinusGeffarth

+0

yup .. Sehr unterschätzte Antwort. –