在iphone ios上的swift 3中弹出

Rea*_*asy 30 iphone popover ios swift3

我正在尝试使用以下代码创建一个弹出菜单:

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
    }
}
Run Code Online (Sandbox Code Playgroud)

这适用于iPad,但是,在iPhone上,弹出窗口占据了整个iPhone屏幕.我只想要一个带箭头的小窗户.我发现了几个教程,但没有一个对我有用.

Ton*_*enu 57

将您的委托方法更改为:

func adaptivePresentationStyle(for controller: UIPresentationController, traitCollection: UITraitCollection) -> UIModalPresentationStyle {
    // return UIModalPresentationStyle.FullScreen
    return UIModalPresentationStyle.none
}
Run Code Online (Sandbox Code Playgroud)