ios - Swift 3 - adaptivePresentationStyle 永远不会被调用

标签 ios swift xcode popover

我正在尝试在 iPhone 中显示弹出窗口。我遵循我在此处找到的建议并使用委托(delegate)“adaptivePresentationStyle”,但从未调用过此函数,并且 ViewController 将始终以全屏模式显示。我有“UIPopoverPresentationControllerDelegate”和以下功能:

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {

        let identifier  = segue.destination.restorationIdentifier ?? ""
        if identifier == "NavigationSetup" {
            if let destinationNav   = segue.destination as? UINavigationController {
                let destination  = destinationNav.topViewController as! SetupTableViewController
                destination.popoverPresentationController?.delegate = self
                destination.popoverPresentationController?.backgroundColor  = UIColor.blue
                if self.myApp.isIpad{
                    destination.preferredContentSize  = CGSize(width: 600, height: 620)
                }else{
                    destination.preferredContentSize  = CGSize(width: 0.8 * self.view.frame.size.width, height: 0.8 * self.view.frame.size.height)
                }

                self.cellAnimations.fade(image: self.imageBlur, initOpacity: 0, endOpacity: 1, time: 0.3, completion: nil)
                destination.setupDismiss = {[weak self] () in
                    if let weakSelf = self{
                        weakSelf.cellAnimations.fade(image: weakSelf.imageBlur, initOpacity: 1, endOpacity: 0, time: 0.3, completion: nil)
                    }
                }

            }
        }

    }
    func adaptivePresentationStyle(for controller:UIPresentationController) -> UIModalPresentationStyle {
        print("adaptive was called")
        return .none
    }

那么,我在这里缺少什么?

最佳答案

首先,设置断点以确保调用此行:

destination.popoverPresentationController?.delegate = self

更好的是,像这样重写,并设置一个断点以确保正在调用内线:

if let pop = destination.popoverPresentationController {
    pop.delegate = self
}

如果是,那就太好了!在那种情况下,问题可能是实现了错误的委托(delegate)方法。你想要这个:

func adaptivePresentationStyle(for controller: UIPresentationController, 
    traitCollection: UITraitCollection) -> UIModalPresentationStyle {

关于ios - Swift 3 - adaptivePresentationStyle 永远不会被调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41765849/

相关文章:

PFGeoPoint 的 Swift 解析查询不显示多个注释

iphone - FlipView 关闭后如何刷新 View

ios - SQLCipher商业版和FTS3

iphone - 操作 AudioBuffer 的 mData 中的数据

ios - ios中如何解析多个json?

ios - 如何最好地将年、月、日存储到核心数据中

swift - 如何检测 UITableView 标题何时滚动?

ios - iOS 中弹出窗口的黑色透明背景

ios - 导入 mymodel.mlmodel 时出现 CoreML : source file is not valid , 错误

ios - 我在 Xcode 的自动布局部分的底部没有看到 iPhone 6、6S 尺寸来调整我的 View 。我只看到 4s、SE、7 和 7 Plus 尺寸