当前位置:  开发笔记 > IOS > 正文

Swift 3 - 从不调用adaptivePresentationStyle

如何解决《Swift3-从不调用adaptivePresentationStyle》经验,为你挑选了1个好方法。

我试图在iPhone中显示一个popover.我遵循我在这里找到的建议并使用委托"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
    }

那么,我在这里失踪了什么?



1> matt..:

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

destination.popoverPresentationController?.delegate = self

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

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

如果是的话,好!在这种情况下,问题可能是实现错误的委托方法.你要这个:

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

推荐阅读
女女的家_747
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有