2017-01-20 42 views
2

我試圖在iPhone中顯示彈出窗口。我遵循我在這裏找到的建議,並使用委託「adaptivePresentationStyle」,但從未調用此函數,並始終以全屏模式呈現ViewController。我有「UIPopoverPresentationControllerDelegate」和功能波紋管:Swift 3 - adaptivePresentationStyle永遠不會調用

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 
    } 

所以,我在這裏失蹤?

+0

我想...你缺少..'popController.modalPresentationStyle = UIModalPresentationStyle.popover' – TonyMkenu

+0

檢查這個.. http://stackoverflow.com/questions/39972979/popover-in-swift -3-on-iphone-ios/39975346#39975346 – TonyMkenu

+0

謝謝你,但我使用的是「目的地」,應該使用「destinationNav」。現在正在工作。 – ClaytonAV

回答

5

首先,設置斷點,以確保這條線被稱爲:

destination.popoverPresentationController?.delegate = self 

更妙的是,重寫這個樣子,並設置一個斷點,以確保內線被稱爲:

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

如果是,好!在這種情況下,問題可能是實現錯誤的委託方法。你想這樣的:

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

謝謝你,你是對的,我應該使用「destinationNav」而不是「目的地」。 – ClaytonAV

0

也許你並沒有提出很好

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

定製的模態呈現呈現並使其動畫,同時提出應該做的伎倆

相關問題