2017-01-20 4 views
2

Я пытаюсь показать popover в 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) 

Вручения пользовательской модальной презентацию и сделать его анимированным во время презентации должна сделать трюк