Skip to content

Instantly share code, notes, and snippets.

@aravindhkumar23
Last active May 31, 2016 11:10
Show Gist options
  • Save aravindhkumar23/b47d6506b1b388ee069cb1d451af26c1 to your computer and use it in GitHub Desktop.
Save aravindhkumar23/b47d6506b1b388ee069cb1d451af26c1 to your computer and use it in GitHub Desktop.
Add animation for swipe from left to right -Swift
import UIKit
import QuartzCore
enum CustomSegueAnimation {
case SwipeFromleft
}
// MARK: Segue class
class CustomSegue: UIStoryboardSegue {
var animationType = CustomSegueAnimation.SwipeFromleft
override func perform() {
switch animationType {
case .SwipeFromleft:
animateSwipeFromleft()
}
}
private func animateSwipeFromleft() {
let toViewController = destinationViewController
let fromViewController = sourceViewController
let containerView = fromViewController.view.superview
let screenBounds = UIScreen.mainScreen().bounds
let finalToFrame = screenBounds
let finalFromFrame = CGRectOffset(finalToFrame, screenBounds.size.width,0)
toViewController.view.frame = CGRectOffset(finalToFrame, -screenBounds.size.width,0) //(finalToFrame, 0, -screenBounds.size.height)
containerView?.addSubview(toViewController.view)
UIView.animateWithDuration(0.25, animations: {
print("animation complete")
toViewController.view.frame = finalToFrame
fromViewController.view.frame = finalFromFrame
let fromVC = self.sourceViewController
let toVC = self.destinationViewController
fromVC.navigationController?.pushViewController(toVC, animated: false)
}, completion: { finished in
print("animation completeadsasasaaaa")
})
}
}
override func viewDidLoad() {
super.viewDidLoad()
/* ######################### swipe recognizer start ################################### */
let rightSwipe = UISwipeGestureRecognizer(target: self, action: #selector(YouViewController.handleSwipes(_:)))
rightSwipe.direction = .Right
}
func handleSwipes(sender:UISwipeGestureRecognizer) {
if (sender.direction == .Right) {
print("Swipe Right -- to home screen")
performSegueWithIdentifier("main", sender: self)
}
}
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if(segue.identifier == "main"){
print("prepare for segue main")
(segue as! CustomSegue).animationType = .SwipeFromleft
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment