Advertisement
Guest User

Custom Segue Implementation

a guest
Jan 3rd, 2016
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Swift 1.70 KB | None | 0 0
  1. import UIKit
  2.  
  3. class SlideOverSegue: UIStoryboardSegue {
  4.    
  5.     override func perform() {
  6.         let firstView = self.sourceViewController.view as UIView!
  7.         let secondView = self.destinationViewController.view as UIView!
  8.         let screenSize = UIScreen.mainScreen().bounds.size
  9.         let window = UIApplication.sharedApplication().keyWindow
  10.        
  11.         secondView.frame = CGRectMake(0.0, screenSize.height, screenSize.width, screenSize.height)
  12.         window?.insertSubview(secondView, aboveSubview: firstView)
  13.        
  14.         firstView.layer.anchorPoint = CGPoint(x: 0.0, y: 0.0)
  15.         firstView.layer.position = CGPoint(x: 0.0, y: 0.0)
  16.        
  17.         UIView.animateWithDuration(2, delay: 0, options: .CurveEaseInOut, animations: {
  18.            
  19.             print(firstView.frame)
  20.            
  21.             let offset: CGFloat = 25
  22.             let offsetX = 2 * (offset / firstView.frame.width)
  23.             let offsetY = 2 * (offset * (firstView.frame.height / firstView.frame.width) / firstView.frame.height)
  24.            
  25.             let transform = CGAffineTransformScale(CGAffineTransformIdentity, 1 - offsetX, 1 - offsetY)
  26.             firstView.transform = transform
  27.             firstView.layer.position = CGPoint(x: offset, y: offset)
  28.            
  29.         }, completion: nil)
  30.        
  31.         UIView.animateWithDuration(5, delay: 0.05, options: .CurveEaseOut, animations: {
  32.            
  33.             secondView.frame = CGRectMake(0.0, 0.0, screenSize.width, screenSize.height)
  34.            
  35.             }) { finished -> Void in
  36.                 self.sourceViewController.presentViewController(self.destinationViewController, animated: false, completion: nil)
  37.         }
  38.     }
  39.    
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement