0

In my SpriteKit games, all in landscape, I am showing a SafariViewController.

func showSafariViewController(forURL url: String) {
    guard let validURL = NSURL(string: url) else { return }

    let safariViewController = SFSafariViewController(URL: validURL)
    safariViewController.delegate = self
    // present safariViewController
}

The open/closing animation is from the right side.

When using the Facebook SDK to login with Facebook it looks like they are using a SafariViewController as well and it animates in/out from the bottom.

Is there a way I can achieve this as well?

crashoverride777
  • 10,581
  • 2
  • 32
  • 56

1 Answers1

2

FacebookSDK behavior is a little bit tricky: they added SafariVC to another view controller (containerVC) and then present containerVC, not SafariVC.

I write an example that implements this behavior (not sure about autoresizing mask, may be you need to use autolayout, but it is up to you):

  let containerVC = UIViewController()
  let url = URL(string: "https://yandex.ru")!
  let safariVC = SFSafariViewController(url: url)
  containerVC.addChildViewController(safariVC)
  safariVC.view.autoresizingMask = [ .flexibleWidth, .flexibleHeight ]
  safariVC.view.frame = containerVC.view.frame
  containerVC.view.addSubview(safariVC.view)
  safariVC.didMove(toParentViewController: containerVC)
  self.present(containerVC, animated: true, completion: nil)
Roman Ermolov
  • 7,898
  • 5
  • 27
  • 35
  • Thank you very much. I'll give this a shot tomorrow and report back. There is another stack question I saw that does it the same way but instead of a viewController they added it to a UINav bar with the top bar set to hidden. This initially seems to work but I noticed that if you open and close safari VC in fast succession you can get a white screen with no buttons/interface. I could never replicate that just adding it normally. I try with a VC and let you know. Thanks again – crashoverride777 Aug 08 '16 at 23:10
  • Did it help in you case? – Roman Ermolov Aug 12 '16 at 05:49
  • Sorry for the late reply. I am on holiday and didn't have time until today. Your answer worked great and I can also not replicate the issue with having a blank safari page with no UI. Thanks again you for the help. – crashoverride777 Aug 13 '16 at 14:18