在 iphone ios 上的 swift 3 中弹出 [英] Popover in swift 3 on iphone ios
本文介绍了在 iphone ios 上的 swift 3 中弹出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用以下代码制作弹出菜单:
I am trying to make a popover menu 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
}
}
这适用于 iPad,但在 iPhone 上,弹出窗口会占据整个 iPhone 屏幕.我只想要一个带箭头的小窗户.我找到了几个教程,但没有一个对我有用.
This is working on iPad, but, on an iPhone, the popup takes the whole iPhone screen. I just want a small window with an arrow. I found several tutorials but none worked for me.
推荐答案
将您的委托方法更改为:
Change your delegate method to:
func adaptivePresentationStyle(for controller: UIPresentationController, traitCollection: UITraitCollection) -> UIModalPresentationStyle {
// return UIModalPresentationStyle.FullScreen
return UIModalPresentationStyle.none
}
这篇关于在 iphone ios 上的 swift 3 中弹出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文