2

I am trying to show a popover in an iPhone. I am following the suggestions that i found here and using the delegate "adaptivePresentationStyle", but this function is never called and the ViewController it will always presented in fullscreen mode. I have the "UIPopoverPresentationControllerDelegate" and the functions bellow:

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
    }

So, what i am missing here ?

ClaytonAV
  • 95
  • 14
  • I think.. you are missing.. `popController.modalPresentationStyle = UIModalPresentationStyle.popover` – TonyMkenu Jan 20 '17 at 16:57
  • check this.. http://stackoverflow.com/questions/39972979/popover-in-swift-3-on-iphone-ios/39975346#39975346 – TonyMkenu Jan 20 '17 at 16:57
  • Thanks man, but i was using the "destination" and should be using the "destinationNav". It´s working now. – ClaytonAV Jan 20 '17 at 17:02

2 Answers2

6

First, set a breakpoint to make sure this line is being called:

destination.popoverPresentationController?.delegate = self

Even better, rewrite like this, and set a breakpoint to make sure the inner line is being called:

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

If it is, good! In that case the problem is probably that implementing the wrong delegate method. You want this:

func adaptivePresentationStyle(for controller: UIPresentationController, 
    traitCollection: UITraitCollection) -> UIModalPresentationStyle {
matt
  • 515,959
  • 87
  • 875
  • 1,141
0

Maybe you did not present it well

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

Presenting with custom Modal presentation and making it animated while presenting should do the trick

Faruk Duric
  • 794
  • 1
  • 7
  • 10