gpt4 book ai didi

ios - Popover 保持模态呈现

转载 作者:搜寻专家 更新时间:2023-11-01 06:37:34 24 4
gpt4 key购买 nike

我正在尝试在点击图像时添加一个弹出窗口,但它一直以模态方式呈现。这个问题/主题的每个答案都建议添加 adaptivePresentationStyleForPresentationController 但它对我不起作用。我正在尝试在 iPhone 上执行此操作。这是我的代码:

class ParkingInfoTableViewController: UITableViewController, UIPopoverPresentationControllerDelegate {
...
func presentPopover(sender:UITapGestureRecognizer) {
let storyboard : UIStoryboard = UIStoryboard(name: "Main",bundle: nil)
let infoViewController = storyboard.instantiateViewControllerWithIdentifier("ImagesInfoPopupViewController")
infoViewController.modalPresentationStyle = .Popover
infoViewController.preferredContentSize = CGSizeMake(150, 75)

let popoverPresentationViewController = infoViewController.popoverPresentationController
popoverPresentationViewController?.permittedArrowDirections = .Any
popoverPresentationController?.delegate = self
popoverPresentationViewController?.sourceView = sender.view
popoverPresentationViewController?.sourceRect = CGRect(
x: sender.locationInView(sender.view).x,
y: sender.locationInView(sender.view).y,
width: 1,
height: 1)

self.presentViewController(infoViewController, animated: true, completion: nil)

}

func adaptivePresentationStyleForPresentationController(controller: UIPresentationController) -> UIModalPresentationStyle {
return .None
}

带有图像的单元格是:

        let cell = tableView.dequeueReusableCellWithIdentifier(AppConstants.moreInfoCellReusableIdentifier) as! MoreInfoTableViewCell

let tapped = UITapGestureRecognizer(target: self, action: #selector(presentPopover))
tapped.numberOfTapsRequired = 1
cell.securityImage.addGestureRecognizer(tapped)
cell.securityImage.userInteractionEnabled = true

return cell

最佳答案

以下是针对 Swift 3 (Xcode 8) 的解决方案

我在从 Swift 2.2 (Xcode 7) 迁移到 Swift 3 (Xcode 8) 时遇到了这个问题。

对于 UIPopoverPresentationControllerDelegate,我在下面实现了这两个:

public func adaptivePresentationStyle(for controller: UIPresentationController) -> UIModalPresentationStyle {
return .none
}

public func adaptivePresentationStyle(for controller: UIPresentationController, traitCollection: UITraitCollection) -> UIModalPresentationStyle {
return .none
}

在准备 segue 时,我在 prepare(for segue...) 中做了以下操作:

let popover = segue.destination
popover.popoverPresentationController?.delegate = self
popover.modalPresentationStyle = .popover

假设您有一个用于弹出框 Controller 的类,在 viewDidLoad() 中您可以复制以下内容:

super.viewDidLoad()
...
self.preferredContentSize = CGSize(width: 123, height: 456)

最后,我在 Storyboard中定义的 segue 配置如下:

  • 类型:呈现为 Popover
  • anchor :一个按钮栏项目(会因您的实现而异)
  • 方向:默认全部选中

关于ios - Popover 保持模态呈现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39648730/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com