ReasyEasyPeasy ReasyEasyPeasy - 1 month ago 111
iOS Question

Popover in swift 3 on iphone ios

I try to make a popover menue with the following code:

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
}
}


thats working on an ipad. But on an Iphone the popup takes the whole place of the iphone screen. I just want a small window with an arrow. I found several tutorials but no one worked for me.

Answer

Change your delegate method to:

func adaptivePresentationStyle(for controller: UIPresentationController) -> UIModalPresentationStyle {
        // return UIModalPresentationStyle.FullScreen
        return UIModalPresentationStyle.none
    }
Comments