Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // Login.swift
- // AnimationProject
- //
- // Created by Camilo López on 19/07/17.
- // Copyright © 2017 webprogramo. All rights reserved.
- //
- import UIKit
- class Login: UIViewController {
- //Linked objects
- @IBOutlet weak var lblLogin: UILabel!
- @IBOutlet weak var txtUser: UITextField!
- @IBOutlet weak var txtPassword: UITextField!
- @IBOutlet weak var btnLogin: UIButton!
- var lblPosition:CGRect?
- var userPosition:CGRect?
- var passPosition:CGRect?
- var btnPosition:CGRect?
- override func viewDidLoad() {
- super.viewDidLoad()
- // Here we are gonna write animation settings
- self.lblPosition = lblLogin.frame
- self.userPosition = txtUser.frame
- self.passPosition = txtPassword.frame
- self.btnPosition = btnLogin.frame
- //old way
- //self.lblLogin.frame = CGRect(x: 0, y: self.lblLogin.layer.position.y, width: self.lblLogin.frame.size.width, height: self.lblLogin.frame.size.width)
- //new way
- self.position(self.lblLogin, x: 0, y: nil, hidden: false)
- self.position(self.btnLogin, x: nil, y: self.view.frame.size.height + self.btnLogin.frame.size.height, hidden: false)
- self.txtUser.alpha = 0
- self.txtPassword.alpha = 0
- UIView.animate(withDuration: 1.0, delay: 0, options: .curveEaseIn, animations: {
- self.lblLogin.frame = self.lblPosition!
- self.txtUser.alpha = 1
- self.txtPassword.alpha = 1
- self.btnLogin.frame = self.btnPosition!
- }) { (Bool) in
- print("complete")
- }
- }
- func position(_ view_:UIView, x:CGFloat?, y:CGFloat?, hidden:Bool ){
- var finalx:CGFloat = view.layer.position.x
- var finaly:CGFloat = view.layer.position.y
- if var _x = x{
- if(hidden){
- if _x == 0.0{
- _x = _x - view_.frame.width
- }
- }
- finalx = _x
- }
- if var _y = y{
- if(hidden){
- if _y == 0.0{
- _y = _y - view_.frame.height
- }
- }
- finaly = _y
- }
- view_.frame = CGRect(x: finalx, y: finaly, width: view_.frame.width, height: view_.frame.height)
- }
- override func didReceiveMemoryWarning() {
- super.didReceiveMemoryWarning()
- // Dispose of any resources that can be recreated.
- }
- @IBAction func tapLoginBtn(_ sender: Any) {
- }
- /*
- // MARK: - Navigation
- // In a storyboard-based application, you will often want to do a little preparation before navigation
- override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
- // Get the new view controller using segue.destinationViewController.
- // Pass the selected object to the new view controller.
- }
- */
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement