簡體   English   中英

Swift 3-從不調用adaptivePresentationStyle

[英]Swift 3 - adaptivePresentationStyle is never called

我正在嘗試在iPhone中顯示彈出窗口。 我遵循我在這里找到的建議,並使用了代理“ 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
}

如果是這樣,那就好! 在那種情況下,問題可能出在實現錯誤的委托方法上。 你要這個:

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

也許你介紹得不好

let vc = UIViewController()
vc.modalPresentationStyle = .custom;
vc.transitioningDelegate = self;
self.present(vc, animated: true, completion: nil)

呈現自定義的模態呈現並在呈現時使其具有動畫效果應該可以解決問題

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM