Last active
October 29, 2015 07:24
-
-
Save speaktoalvin/1c1ac80ef3bf9aaab461 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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