daily pastebin goal
15%
SHARE
TWEET

Untitled

a guest Jul 20th, 2017 56 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //
  2. //  Login.swift
  3. //  AnimationProject
  4. //
  5. //  Created by Camilo López on 19/07/17.
  6. //  Copyright © 2017 webprogramo. All rights reserved.
  7. //
  8.  
  9. import UIKit
  10.  
  11. class Login: UIViewController {
  12.    
  13.    
  14.     //Linked objects
  15.     @IBOutlet weak var lblLogin: UILabel!
  16.     @IBOutlet weak var txtUser: UITextField!
  17.     @IBOutlet weak var txtPassword: UITextField!
  18.     @IBOutlet weak var btnLogin: UIButton!
  19.    
  20.     var lblPosition:CGRect?
  21.     var userPosition:CGRect?
  22.     var passPosition:CGRect?
  23.     var btnPosition:CGRect?
  24.    
  25.    
  26.    
  27.     override func viewDidLoad() {
  28.         super.viewDidLoad()
  29.  
  30.         // Here we are gonna write animation settings
  31.         self.lblPosition = lblLogin.frame
  32.         self.userPosition = txtUser.frame
  33.         self.passPosition = txtPassword.frame
  34.         self.btnPosition = btnLogin.frame
  35.        
  36.         //old way
  37.         //self.lblLogin.frame = CGRect(x: 0, y: self.lblLogin.layer.position.y, width: self.lblLogin.frame.size.width, height: self.lblLogin.frame.size.width)
  38.         //new way
  39.         self.position(self.lblLogin, x: 0, y: nil, hidden: false)
  40.         self.position(self.btnLogin, x: nil, y: self.view.frame.size.height + self.btnLogin.frame.size.height, hidden: false)
  41.         self.txtUser.alpha = 0
  42.         self.txtPassword.alpha = 0
  43.        
  44.         UIView.animate(withDuration: 1.0, delay: 0, options: .curveEaseIn, animations: {
  45.            
  46.            self.lblLogin.frame = self.lblPosition!
  47.            self.txtUser.alpha = 1
  48.            self.txtPassword.alpha = 1
  49.            self.btnLogin.frame = self.btnPosition!
  50.            
  51.         }) { (Bool) in
  52.             print("complete")
  53.         }
  54.        
  55.        
  56.     }
  57.    
  58.     func position(_ view_:UIView, x:CGFloat?, y:CGFloat?, hidden:Bool ){
  59.        
  60.         var finalx:CGFloat = view.layer.position.x
  61.         var finaly:CGFloat = view.layer.position.y
  62.        
  63.        
  64.         if var _x  = x{
  65.             if(hidden){
  66.                 if _x == 0.0{
  67.                     _x = _x - view_.frame.width
  68.                 }
  69.             }
  70.             finalx = _x
  71.         }
  72.        
  73.         if var _y  = y{
  74.             if(hidden){
  75.                
  76.                 if _y == 0.0{
  77.                     _y = _y - view_.frame.height
  78.                 }
  79.             }
  80.             finaly = _y
  81.            
  82.         }
  83.        
  84.         view_.frame = CGRect(x: finalx, y: finaly, width: view_.frame.width, height: view_.frame.height)
  85.        
  86.     }
  87.  
  88.     override func didReceiveMemoryWarning() {
  89.         super.didReceiveMemoryWarning()
  90.         // Dispose of any resources that can be recreated.
  91.     }
  92.    
  93.     @IBAction func tapLoginBtn(_ sender: Any) {
  94.        
  95.     }
  96.  
  97.     /*
  98.     // MARK: - Navigation
  99.  
  100.     // In a storyboard-based application, you will often want to do a little preparation before navigation
  101.     override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
  102.         // Get the new view controller using segue.destinationViewController.
  103.         // Pass the selected object to the new view controller.
  104.     }
  105.     */
  106.  
  107. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top