我有一个项目,我正在使用UIPopoverPresentationController,我想将其显示为iPhone和iPad的弹出窗口。即使在只有一个带有单个UIButton的空白Storyboard的独立项目中,以下代码也会导致生成全屏模式弹出窗口。我已经多次看到类似于此问题的问题了,但是每个人似乎都通过返回.None for adaptivePresentationStyleForPresentationController来解决它,但即使包括那个也没有为我修复它。我有一个带有以下代码的ViewController - 我缺少什么?
import UIKit
class ViewController: UIViewController, UIPopoverPresentationControllerDelegate {
@IBOutlet weak var thatButton: UIButton!
@IBAction func presentPopoverController(sender: UIButton) {
let popVC = UIViewController() //(nibName: "CameraPopover", bundle: nil)
popVC.view.backgroundColor = UIColor.blueColor()
popVC.modalPresentationStyle = .Popover
popVC.preferredContentSize = CGSize(width: 100, height: 100)
popVC.view.layer.borderWidth = 5
popVC.view.layer.borderColor = UIColor.blackColor().CGColor
self.presentViewController(popVC, animated: true, completion: nil)
let popController = popVC.popoverPresentationController
popController!.delegate = self
}
func prepareForPopoverPresentation(popoverPresentationController: UIPopoverPresentationController) {
popoverPresentationController.permittedArrowDirections = .Down
popoverPresentationController.sourceView = self.thatButton
popoverPresentationController.sourceRect = self.thatButton.frame
}
func adaptivePresentationStyleForPresentationController(controller: UIPresentationController) -> UIModalPresentationStyle {
return .None
}
func adaptivePresentationStyleForPresentationController(controller: UIPresentationController, traitCollection: UITraitCollection) -> UIModalPresentationStyle {
return .None
}
}