2016-10-11 29 views
23

我試圖讓酥料餅的菜單用下面的代碼:酥料餅在SWIFT 3 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 
    } 
} 

這是工作的iPad,但是,在iPhone上,彈出佔用了整個iPhone的屏幕。我只想要一個帶箭頭的小窗戶。我發現了幾個教程,但都沒有爲我工作。

+0

據我所知,這是蘋果的預期的行爲,則對iphone – Fonix

+0

你的代碼它的工作對我來說沒有彈出....但你的委託這是不正確的 – TonyMkenu

回答

42

您的委託方法更改爲:

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

這讓我瘋狂,非常感謝你! – ur3k

+0

感謝好友節省我的時間 – Daddy

+1

@TonyMkenu不能在iPhone上工作,請讓我知道它是如何工作的? –