2016-10-11 3 views
23

Ich versuche, ein popover Menü mit dem folgenden Code zu machen:Popover in swift 3 auf iphone ios

import UIKit 

class BeobachtungViewController: UIViewController, UIPopoverPresentationControllerDelegate { 


    @IBAction func addClicked(_ sender: AnyObject) { 
     // get a reference to the view controller for the popover 
     let popController = UIStoryboard(name: "Personenakte", bundle: nil).instantiateViewController(withIdentifier: "popoverId") 

     // set the presentation style 
     popController.modalPresentationStyle = UIModalPresentationStyle.popover 

     // set up the popover presentation controller 
     popController.popoverPresentationController?.permittedArrowDirections = UIPopoverArrowDirection.up 
     popController.popoverPresentationController?.delegate = self 
     popController.popoverPresentationController?.sourceView = sender as! UIView // button 
     popController.popoverPresentationController?.sourceRect = sender.bounds 

     // present the popover 
     self.present(popController, animated: true, completion: nil) 
    } 

    // UIPopoverPresentationControllerDelegate method 
    func adaptivePresentationStyleForPresentationController(controller: UIPresentationController) -> UIModalPresentationStyle { 
     // Force popover style 
     return UIModalPresentationStyle.none 
    } 
} 

Dieses auf iPad arbeitet, aber auf einem iPhone, nimmt das Fenster den ganzen iPhone-Bildschirm. Ich möchte nur ein kleines Fenster mit einem Pfeil. Ich habe mehrere Tutorials gefunden, aber keine funktionierte für mich.

+0

soweit ich weiß, dass das gewünschte Verhalten von Apfel, gibt es für mich keine Pop-ups auf iphone – Fonix

+0

Code es funktioniert .... aber Ihre Stellvertretung es ist nicht korrekt – TonyMkenu

Antwort

42

Ihre delegierte Methode ändern:

func adaptivePresentationStyle(for controller: UIPresentationController, traitCollection: UITraitCollection) -> UIModalPresentationStyle { 
    // return UIModalPresentationStyle.FullScreen 
    return UIModalPresentationStyle.none 
} 
+0

Das hat mich verrückt gemacht, vielen Dank! – ur3k

+0

Danke Freund für das Speichern meiner Zeit – Daddy

+1

@TonyMkenu Funktioniert nicht in iPhone, lass es mich wissen, wie es funktioniert? –