Present Safari View Controller Modally instead of Push

by

When I launch safari view controller(SFSafariViewController) by way of present(_:animated:completion:) method, I do not get the default modal transition behaviour, instead the transition is that of push (sliding in from the right), as if I called pushViewController:animated:

SFSafariViewController

An object that provides a visible standard interface for browsing the web.

The solution was to set transition delegate to self or controller from where safari controller is being presented. Lastly adopt the UIViewControllerTransitioningDelegate with no need to implement any of the protocol methods as they are optional.

UIViewControllerTransitioningDelegate

A set of methods that vend objects used to manage a fixed-length or interactive transition between view controllers.


Neat solution:




let svc = SFSafariViewController(url: url)
svc.transitioningDelegate = self //neat solution to make it use default modal presentation instead of push
present(svc, animated: true, completion: nil)

Remember again, we need to adopt the UIViewControllerTransitioningDelegate protocol in our view controller, but there are no required functions to implement.

You might also like: AVAudioPlayer not playing any sound

You might also like: How to Get Substring With NSRange in Swift 5

You might also like: How to Fix Warning Attempt To Present UIAlertController

More Articles

Recommended posts