I had a working user UIPresentationController before Xcode beta 2 and iOS 10 beta 2. I did not change any code, but the presentation now provides a standard modal presentation.
There is a note in the Apple sample code for the UIPresentationController:
For presentations that will use a custom view controller, there may also be transitioningDelegate for this view controller. This avoids introducing another object or embedding into a view source.
transitioningDelegate does not contain a link to its target. To prevent presentationController from being released before calling -presentViewController: animated: completion: the NS_VALID_UNTIL_END_OF_SCOPE attribute is added to the declaration.
I tested transitioningDelegate on the presented view controller before and after the presentation. Before it will be my custom UIPresentationController, but after it is zero. I assume the link is being released, but I cannot find the equivalent of NS_VALID_UNTIL_END_OF_SCOPE in Swift. EDIT: I checked that transitioningDelegate is configured only before the presentation, and then is zero when it is time to submit.
My code in the view controller:
@IBAction func buttonAction(_ sender: UIButton) { let secondViewController = storyboard!.instantiateViewController(withIdentifier: "NewViewController") as! NewViewController let presentationController = MyPresentationController(presentedViewController: secondViewController, presenting: self) presentationController.initialFrame = button.frame secondViewController.transitioningDelegate = presentationController // Move map let pixelsToMove: CGFloat = mapView.frame.height / 4 let region = self.mapView.region self.mapView.setRegion(region, offsetBy: pixelsToMove, animated: true) // Delegate to NewViewController secondViewController.mapView = mapView mapView.delegate = secondViewController print(secondViewController.transitioningDelegate) UIView.animate(withDuration: 0.3, animations: { let tabBar = self.tabBarController!.tabBar tabBar.frame.origin.y += tabBar.frame.height self.present(secondViewController, animated: true, completion: nil) }) }
And my code in the UIPresentationController:
override init(presentedViewController: UIViewController, presenting presentingViewController: UIViewController?) { super.init(presentedViewController: presentedViewController, presenting: presentingViewController) presentedViewController.modalPresentationStyle = .custom }
ios uiviewcontroller swift uipresentationcontroller
jjatie
source share