Skip to content

Instantly share code, notes, and snippets.

@speaktoalvin
Last active October 29, 2015 07:24
Show Gist options
  • Save speaktoalvin/1c1ac80ef3bf9aaab461 to your computer and use it in GitHub Desktop.
Save speaktoalvin/1c1ac80ef3bf9aaab461 to your computer and use it in GitHub Desktop.
// Main ViewController
import UIKit
import SafariServices
class ViewController: UIViewController, SFSafariViewControllerDelegate, UIViewControllerTransitioningDelegate {
let transitionManager : HelloTransition = HelloTransition()
@IBAction func showSafariViewController(sender: AnyObject){
let safariViewController = IDMSafariViewController(URL: NSURL(string: "http://idreamcode.com")!)
safariViewController.delegate = self;
safariViewController.transitioningDelegate = self.transitionManager
safariViewController.modalPresentationStyle = UIModalPresentationStyle.Custom
self.transitionManager.transitionTo = kToSAFARIVC
self.presentViewController(safariViewController, animated: true) { () -> Void in
let recognizer = UIScreenEdgePanGestureRecognizer(target: self, action: "handleGesture:")
recognizer.edges = UIRectEdge.Left
safariViewController.edgeView?.addGestureRecognizer(recognizer)
}
}
func handleGesture(recognizer:UIScreenEdgePanGestureRecognizer) {
switch recognizer.state {
case .Began: ()
case .Changed:dismissViewControllerAnimated(true, completion: nil)
case .Ended, .Cancelled:
(recognizer.velocityInView(view).x < 0) ? () :
dismissViewControllerAnimated(true, completion: nil)
default: ()
}
}
func safariViewControllerDidFinish(controller: SFSafariViewController)
{
controller.dismissViewControllerAnimated(true, completion: nil)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment