这个问题已经被提前3次问过Swift 4我觉得我有类似的问题。
我的UIPopoverPresentationController
在纵向+横向中显示为全窗口弹出窗口,添加.None
并不能解决问题。我通过xcode使用iPhone 6作为模拟器。
这就是我所拥有的:
@objcMembers class ViewController: UITableViewController, UIGestureRecognizerDelegate, UIPopoverPresentationControllerDelegate {
func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if segue.identifier == "settingsPopoverSegue" {
let buttonItemView = settingsButton.value(forKey: "view")
let viewForSource = (buttonItemView as! UIView)
popoverPresentationController?.sourceView = viewForSource
let popoverViewController = segue.destination
popoverViewController.popoverPresentationController!.delegate = self
popoverViewController.modalPresentationStyle = UIModalPresentationStyle.popover
popoverViewController.popoverPresentationController?.sourceRect = CGRect(x: view.center.x, y: view.center.y, width: 0, height: 0)
popoverViewController.popoverPresentationController?.permittedArrowDirections = UIPopoverArrowDirection(rawValue: 0)
}
}
func adaptivePresentationStyleForPresentationController(controller: UIPresentationController) -> UIModalPresentationStyle {
return UIModalPresentationStyle.none
}
}
我将从故事板上的uibarbutton连接到popoverViewController的segue。
上面更新的代码 - 好吧,所以我添加了一个sourceView,但是popover仍在全屏滑动。我仍然必须遗漏一些东西。有什么想法吗?
第二次更新:将其置于设置按钮的操作中,iphone仍显示为全屏:
@IBAction func settingsTapped(segue: UIStoryboardSegue, sender: UIBarButtonItem) {
if segue.identifier == "settingsPopoverSegue" {
let buttonItemView = settingsButton.value(forKey: "view")
let viewForSource = (buttonItemView as! UIView)
popoverPresentationController?.sourceView = viewForSource
let popoverViewController = segue.destination
popoverViewController.popoverPresentationController!.delegate = self
popoverViewController.modalPresentationStyle = UIModalPresentationStyle.popover
popoverViewController.popoverPresentationController?.sourceRect = CGRect(x: view.center.x, y: view.center.y, width: 0, height: 0)
popoverViewController.popoverPresentationController?.permittedArrowDirections = UIPopoverArrowDirection(rawValue: 0)
}
}
答案 0 :(得分:0)
请给一个源矩形打开它。如果要从特定点打开它,请提供源视图。
let buttonItemView = YourBarButtonItem.value(forKey: "view")
et buttonItem = (buttonItemView as! UIView)
popoverPresentationController?.sourceRect = Your Rect
popoverPresentationController?.sourceView = buttonItem