Ad

Our DNA is written in Swift
Jump

Swiping Away SFSafariViewController

A client of ours asked to be able to dismiss Safari View Controller via swipe, as seen in Tweetboot 4. We first tried another open source project which supposedly was the solution that Paul from Tapbots came up with, but found some issues with that. Here’s now our working solution, by Cocoanetics team member Stefan Gugarel.

Paul Hadad from Tapbots wrote:

This is an explanation of the SFVC “hack” i’m using. @stringcode and I independently came up with same trick.

He referred us to a blog post by stringcode86. The article shows how SFSafariViewController can be swiped away on the left side.

When testing this project my client and me found some stuff that is not working like expected:

  • There were situations where the SFSafariViewController was not getting released. When you want to present a new one this does not work because you can only have one instance of SFSafariViewController at one point in time. So keep this in mind.
  • In an another situation a white ViewController was shown instead of SFSafariViewController.

This project is done with interactive transitions for modal presentation. I tried a lot of stuff to solve the problems but I ended up switching the presentation to push / pop. With this change it seems that all earlier problems are gone.

Swiping Away SFSafariViewController

One difficult part for me was that in the following sample I want to have a UINavigationBar on my first ViewController but not on the second (SFSafariViewController). The only way I found is to show / hide the NavigationBar in the corresponding ViewControllers in viewWillAppear methods. This also works for the interactive transition between our two view controllers.

override func viewWillAppear(animated: Bool) 
{
  super.viewWillAppear(animated)
 
  self.navigationController?.setNavigationBarHidden(true, animated: animated)
}

Another thing I found out is from what I mentioned earlier: When I come back from Safari and try to press the Show button quickly after that, it is not working. This is because the SFSafariViewController is not released at this point and I can’t show a new one. So I disabled my show button when I tap on it and enable it again in viewWillAppear. With this the user experience is best.

The SwipeSafari sample code can be found on our Swift Examples repo. If anybody ever figures out how to fix the above mentioned project we’d be interested to learn how you managed to fix it.


Categories: Recipes

1 Comment »

Trackbacks

  1. Swiping Away SFSafariViewController | Dinesh Ram Kali.

Leave a Comment