All Projects → VamshiIITBHU14 → UIViewAnimationsHandbook

VamshiIITBHU14 / UIViewAnimationsHandbook

Licence: other
This project takes up all the available UIView animations in Swift4. Each type animation added with an example and expected result in the form of GIF. A glimpse at README would give you a better idea. Do give a star if you like the work.

Programming Languages

swift
15916 projects

Projects that are alternatives of or similar to UIViewAnimationsHandbook

DataStructures-Algorithms
A collections of many CP-based or DSA-based Questions that is stored various algorithms and datastructures to increase coding aptitutde. Anybody with a knack for coding can feel free to add more solutions and questions in the respective folders
Stars: ✭ 15 (-65.12%)
Mutual labels:  computer-science
Grafatko
An app for creating and visualizing graphs and graph-related algorithms.
Stars: ✭ 22 (-48.84%)
Mutual labels:  computer-science
tenacity
A computational thinking game to introduce functions, loops, conditions, and variables
Stars: ✭ 23 (-46.51%)
Mutual labels:  computer-science
awesome-backend
🚀 A curated and opinionated list of resources (English & Russian) for Backend developers | Структурированный список ресурсов для изучения Backend разработки
Stars: ✭ 826 (+1820.93%)
Mutual labels:  computer-science
python-data-structures-and-algorithms
No description or website provided.
Stars: ✭ 57 (+32.56%)
Mutual labels:  computer-science
BackEnd-Squad
Back End Squad Roadmap
Stars: ✭ 24 (-44.19%)
Mutual labels:  computer-science
wtm-udacity-scholars-nanodegree-resources
A List of Resources for Udacity Nanodegrees
Stars: ✭ 15 (-65.12%)
Mutual labels:  computer-science
CS
Computer Science Notes
Stars: ✭ 33 (-23.26%)
Mutual labels:  computer-science
reading-material
Reading schedule and our library of pdfs
Stars: ✭ 19 (-55.81%)
Mutual labels:  computer-science
awesome-readings
List of Awesome Research Articles on Computer Science and Technology
Stars: ✭ 25 (-41.86%)
Mutual labels:  computer-science
CS Offer
后台开发基础知识总结(春招/秋招)
Stars: ✭ 352 (+718.6%)
Mutual labels:  computer-science
particle-animations
Animate your iOS app with particle systems
Stars: ✭ 14 (-67.44%)
Mutual labels:  ios-animation
curr
All curricular materials for Bootstrap course modules
Stars: ✭ 13 (-69.77%)
Mutual labels:  computer-science
CSIndex
Transparent data about Brazilian scientific production in Computer Science
Stars: ✭ 34 (-20.93%)
Mutual labels:  computer-science
HyperGraphLib
C++ Hypergraph modelling Library using Boost and OpenMP with some algorithms, including isomorphism using Gecode.
Stars: ✭ 19 (-55.81%)
Mutual labels:  computer-science
CS-Learning-Resources
Learning Resources for Those New to Computer Science
Stars: ✭ 19 (-55.81%)
Mutual labels:  computer-science
Codex
A free note-taking software for programmers and Computer Science students
Stars: ✭ 242 (+462.79%)
Mutual labels:  computer-science
js-data-structures
🌿 Data structures for JavaScript
Stars: ✭ 56 (+30.23%)
Mutual labels:  computer-science
HKU-Thesis-Template
HKU Thesis Template
Stars: ✭ 36 (-16.28%)
Mutual labels:  computer-science
AlgorithmsAndDataStructure
Algorithms And DataStructure Implemented In Python, Java & CPP, Give a Star 🌟If it helps you
Stars: ✭ 724 (+1583.72%)
Mutual labels:  computer-science

UIViewAnimationsHandbook

HOW TO USE:

Just pick the chapter you want in Xcode playground and Run the program. Make sure the Assistant Editor (Live View) is turned on. Please refer to the screenshot below.

screen shot 2018-11-17 at 10 22 44 pm

CHAPTER 1:

import UIKit
import PlaygroundSupport


class MaiusenViewController : UIViewController{
    var demoView = UIView(frame: CGRect(x: 0, y: 60, width: 120, height: 40))
    
    override func viewDidLoad() {
        self.view.backgroundColor = UIColor.blue
        demoView.backgroundColor = UIColor.green
        self.view.addSubview(demoView)
        
        title = "UIView Animations"
    }
    override func viewWillAppear(_ animated: Bool) {
        demoView.center.x = -self.view.bounds.width
    }
    
    override func viewDidAppear(_ animated: Bool) {
        UIView.animate(withDuration: 0.5) {
            self.demoView.center.x += 1.5*self.view.bounds.width
            
        }
    }
}

let vc = MainViewController()
let nav = UINavigationController(rootViewController: vc)
PlaygroundPage.current.liveView = nav

RESULT:

a1

CHAPTER 2:

import UIKit
import PlaygroundSupport


class MainViewController : UIViewController{
    var demoView1 = UIView(frame: CGRect(x: 0, y: 60, width: 120, height: 40))
    var demoView2 = UIView(frame: CGRect(x: 0, y: 120, width: 120, height: 40))
    
    override func viewDidLoad() {
        self.view.backgroundColor = UIColor.blue
        demoView1.backgroundColor = UIColor.green
        demoView2.backgroundColor = UIColor.gray
        self.view.addSubview(demoView1)
        self.view.addSubview(demoView2)
        
        title = "UIView Animations"
    }
    override func viewWillAppear(_ animated: Bool) {
        demoView1.center.x = -self.view.bounds.width
        demoView2.center.x = -self.view.bounds.width
    }

    override func viewDidAppear(_ animated: Bool) {
        UIView.animate(withDuration: 0.5) {
            self.demoView1.center.x += 1.5*self.view.bounds.width
            
        }
        
        UIView.animate(withDuration: 1.0, delay: 0.5, options: [], animations: {
            self.demoView2.center.x += 1.5*self.view.bounds.width
        }, completion: nil)
    }
}

let vc = MainViewController()
let nav = UINavigationController(rootViewController: vc)
PlaygroundPage.current.liveView = nav

RESULT:

ezgif com-resize

CHAPTER 3:

import UIKit
import PlaygroundSupport


class MainViewController : UIViewController{
    var demoView = UIView(frame: CGRect(x: 120, y: 60, width: 120, height: 40))
    
    override func viewDidLoad() {
        self.view.backgroundColor = UIColor.white
        demoView.backgroundColor = UIColor.green
        self.view.addSubview(demoView)
        demoView.alpha = 0
        title = "UIView Animations"
    }
    
    override func viewDidAppear(_ animated: Bool) {
        UIView.animate(withDuration: 3.0, delay: 0.5, options: [.repeat], animations: {
            self.demoView.alpha = 1
        }, completion: nil)
        
    }
}

let vc = MainViewController()
let nav = UINavigationController(rootViewController: vc)
PlaygroundPage.current.liveView = nav

RESULT:

ezgif com-resize

CHAPTER 4:

import UIKit
import PlaygroundSupport


class MainViewController : UIViewController{
    var demoView = UIView(frame: CGRect(x: 0, y: 60, width: 120, height: 40))
    
    override func viewDidLoad() {
        self.view.backgroundColor = UIColor.white
        demoView.backgroundColor = UIColor.green
        self.view.addSubview(demoView)
 
        title = "UIView Animations"
    }
    override func viewWillAppear(_ animated: Bool) {
        demoView.center.x = -self.view.bounds.width
    }
    
    override func viewDidAppear(_ animated: Bool) {
        
        //Repeat
        
//        UIView.animate(withDuration: 0.5, delay: 0, options: [.repeat], animations: {
//             self.demoView.center.x += 1.5*self.view.bounds.width
//        }, completion: nil)
        
        //RepeatAndAutoReverse
        
//        UIView.animate(withDuration: 1.0, delay: 0.5, options: [.repeat ,.autoreverse], animations: {
//            self.demoView.center.x += 1.5*self.view.bounds.width
//        }, completion: nil)
        
        //Repeat And AutoReverse And Ease options
        
        UIView.animate(withDuration: 1.5, delay: 0.4, options: [.repeat, .autoreverse, .curveEaseIn], animations: {
            self.demoView.center.x += 1.5*self.view.bounds.width
        }, completion: nil)
    }
}

let vc = MainViewController()
let nav = UINavigationController(rootViewController: vc)
PlaygroundPage.current.liveView = nav

RESULT:

ezgif com-resize

CHAPTER 5:

import UIKit
import PlaygroundSupport


class MainViewController : UIViewController{
    var demoView = UIView(frame: CGRect(x: 120, y: 60, width: 120, height: 40))
    
    override func viewDidLoad() {
        self.view.backgroundColor = UIColor.blue
        demoView.backgroundColor = UIColor.green
        self.view.addSubview(demoView)
        
        title = "UIView Animations"
    }
    override func viewWillAppear(_ animated: Bool) {
        demoView.center.y = 60
    }
    
    override func viewDidAppear(_ animated: Bool) {
        UIView.animate(withDuration: 5, delay: 0.5,
                       usingSpringWithDamping: 0.2, initialSpringVelocity: 0.5, options: [],
                       animations: {
                        self.demoView.center.y = 150.0
                                }, completion: nil)
    }
}

let vc = MainViewController()
let nav = UINavigationController(rootViewController: vc)
PlaygroundPage.current.liveView = nav

RESULT:

ezgif com-resize

CHAPTER6:

import UIKit
import PlaygroundSupport


class MainViewController : UIViewController{
    var demoView = UIView(frame: CGRect(x: 120, y: 60, width: 120, height: 40))
    
    override func viewDidLoad() {
        self.view.backgroundColor = UIColor.blue
        demoView.backgroundColor = UIColor.green
        self.view.addSubview(demoView)
        demoView.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(demoViewTapped)))
        title = "UIView Animations"
    }
    override func viewWillAppear(_ animated: Bool) {
        demoView.center.y = 80
    }
    
    @objc func demoViewTapped(){
        UIView.animate(withDuration: 2.5, delay: 0.0, usingSpringWithDamping:
            0.2, initialSpringVelocity: 0.2, options: [], animations: {
                self.demoView.bounds.size.width += 80.0
                self.demoView.backgroundColor =
                    UIColor(red: 0.45, green: 0.23, blue: 0.67, alpha: 1.0)
        }, completion:nil)
    }
    override func viewDidAppear(_ animated: Bool) {
        
       
    }
}

let vc = MainViewController()
let nav = UINavigationController(rootViewController: vc)
PlaygroundPage.current.liveView = nav

RESULT:

ezgif com-resize

CHAPTER 7:

import UIKit
import PlaygroundSupport


class MainViewController : UIViewController{
    
    var animationContainerView : UIView!
    var demoView : UIView!
    
    override func viewDidLoad() {
        view.backgroundColor = UIColor.yellow
        animationContainerView = UIView(frame: CGRect(x: 0, y: 0, width: self.view.bounds.width, height: self.view.bounds.height))
        animationContainerView.backgroundColor = UIColor.darkGray
        self.view.addSubview(animationContainerView)
        
        title = "UIView Animations"
    }
    
    override func viewDidAppear(_ animated: Bool) {
        demoView = UIView(frame: CGRect(x: view.center.x-40, y: view.center.y-20, width: 80, height: 40))
        demoView.backgroundColor = UIColor.green
        demoView.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(demoViewTapped)))
        
        //add a subview via transition
        
        UIView.transition(with: animationContainerView, duration: 2.0, options: [.curveEaseIn, .transitionCurlUp], animations: {
            self.animationContainerView.addSubview(self.demoView)
            
        }, completion: nil)
        
    }
    
    @objc func demoViewTapped(){
        //replace views via transition
        
//        UIView.transition(from: animationContainerView, to: demoView, duration: 0.33,
//                          options: .transitionFlipFromTop, completion: nil)
        
        //hide/ remove a subview via transition
        
        UIView.transition(with: animationContainerView, duration: 4.0,
                          options: [.curveEaseOut, .transitionCrossDissolve],
                          animations: {
                            self.demoView.removeFromSuperview()
                            //self.demoView.isHidden = true
        },
                          completion: nil
        )
    }
}

let vc = MainViewController()
let nav = UINavigationController(rootViewController: vc)

PlaygroundPage.current.liveView = nav

RESULT:

ezgif com-resize

CHAPTER 8:

import UIKit
import PlaygroundSupport

class MainViewController : UIViewController{
    
    var demoLabel : UILabel!
    override func viewDidLoad() {
        view.backgroundColor = UIColor.blue
        title = "UIView Animations"
        
        demoLabel = UILabel(frame: CGRect(x: 50, y: 120, width: 180, height: 60))
        demoLabel.backgroundColor = UIColor.green
        demoLabel.text = "Before Transition"
        demoLabel.textAlignment = .center
        demoLabel.layer.cornerRadius = 12
        demoLabel.layer.masksToBounds = true
        self.view.addSubview(demoLabel)
    }
    
    override func viewDidAppear(_ animated: Bool) {
        YAxisTransition(label: demoLabel, text: "After Transition")
    }
    
    func YAxisTransition(label: UILabel, text: String) {
        let tempLabel = UILabel(frame: label.frame)
        tempLabel.text = text
        tempLabel.font = label.font
        tempLabel.layer.cornerRadius = label.layer.cornerRadius
        tempLabel.layer.masksToBounds = true
        tempLabel.textAlignment = label.textAlignment
        tempLabel.textColor = label.textColor
        tempLabel.backgroundColor = label.backgroundColor
        
        
        let tempLabelOffset =
            label.frame.size.height/2.0
        tempLabel.transform =
            CGAffineTransform(translationX: 0.0, y: tempLabelOffset)
                .scaledBy(x: 1.0, y: 0.1)
        
        label.superview?.addSubview(tempLabel)
        
        UIView.animate(withDuration: 2.5, delay: 0, options: .curveLinear, animations: {
            tempLabel.transform = .identity
            label.transform =
                CGAffineTransform(translationX: 0.0, y: tempLabelOffset)
                    .scaledBy(x: 1.0, y: 0.1)
        }) { _ in
            label.text = tempLabel.text
            label.transform = .identity
            tempLabel.removeFromSuperview()
        }
        
    }
    
    func simpleLabelTextTransition(){
        UIView.transition(with: demoLabel, duration: 2.0,
                          options: .transitionCrossDissolve,
                          animations: {
                            self.demoLabel.text = "After Transition"
        },
                          completion: nil
        )
    }
}

let vc = MainViewController()
let nav = UINavigationController(rootViewController: vc)
PlaygroundPage.current.liveView = nav

RESULT::

ezgif com-resize

CHAPTER 9:


swift

import UIKit
import PlaygroundSupport

class MainViewController : UIViewController{
    var demoLabel : UILabel!
    override func viewDidLoad() {
        view.backgroundColor = UIColor.blue
        title = "X-Axis Alpha Transition"
        demoLabel = UILabel(frame: CGRect(x: 25, y: 120, width: 180, height: 60))
        demoLabel.backgroundColor = UIColor.green
        demoLabel.text = "Before Transition"
        demoLabel.textAlignment = .center
        demoLabel.layer.cornerRadius = 12
        demoLabel.layer.masksToBounds = true
        self.view.addSubview(demoLabel)
    }
    override func viewDidAppear(_ animated: Bool) {
        let offsetDeparting = CGPoint(
            x: CGFloat(150),
            y: 0.0)
        XAxisTransition(label: demoLabel, text: "After Transition",
                        offset: offsetDeparting)
    }
    func XAxisTransition(label: UILabel, text: String, offset: CGPoint) {
        let secondLabel = UILabel(frame: label.frame)
        secondLabel.text = text
        secondLabel.font = label.font
        secondLabel.textAlignment = label.textAlignment
        secondLabel.textColor = label.textColor
        secondLabel.backgroundColor = .clear
        secondLabel.transform = CGAffineTransform(translationX: offset.x, y:
            offset.y)
        secondLabel.alpha = 0
        view.addSubview(secondLabel)
        UIView.animate(withDuration: 2.5, delay: 0.0,
                       options: [.repeat, .autoreverse, .curveEaseInOut],
                       animations: {
                        label.transform = CGAffineTransform(translationX: offset.x, y:
                            offset.y)
                        label.alpha = 0.0
        },
                       completion: nil
        )
        UIView.animate(withDuration: 2.5, delay: 0.0, options: [.repeat, .autoreverse, .curveEaseInOut],
                       animations: {
                        secondLabel.transform = .identity
                        secondLabel.alpha = 1.0
        },
                       completion: nil
        )
    }
    func simpleLabelTextTransition() {
        UIView.transition(with: demoLabel, duration: 2.0,
                          options: .transitionCrossDissolve,
                          animations: {
                            self.demoLabel.text = "After Transition"
        },
                          completion: nil
        )
    }
}

let vc = MainViewController()
let nav = UINavigationController(rootViewController: vc)
PlaygroundPage.current.liveView = nav

RESULT:

ezgif com-resize

CHAPTER10:

import UIKit
import PlaygroundSupport


class MainViewController : UIViewController{
    var demoView = UIView(frame: CGRect(x: 60, y: 120, width: 120, height: 40))
    
    override func viewDidLoad() {
        self.view.backgroundColor = UIColor.blue
        demoView.backgroundColor = UIColor.green
        self.view.addSubview(demoView)
        
        title = "UIView Animations"
    }
   
    func planeDepart() {
        let originalCenter = demoView.center
        UIView.animateKeyframes(withDuration: 2.5, delay: 0, animations: {
            
            UIView.addKeyframe(withRelativeStartTime: 0.0, relativeDuration: 0.2, animations: {
                self.demoView.center.x += 40.0
                self.demoView.center.y += 60.0
            })
            
            UIView.addKeyframe(withRelativeStartTime: 0.1, relativeDuration: 0.3) {
                self.demoView.transform = CGAffineTransform(rotationAngle: .pi / 2)
            }

            UIView.addKeyframe(withRelativeStartTime: 0.5, relativeDuration: 0.2, animations: {
                self.demoView.transform = .identity
                self.demoView.center.x -= 20.0
                self.demoView.center.y -= 30.0
            })
            
            UIView.addKeyframe(withRelativeStartTime: 0.6, relativeDuration: 0.2, animations: {
                self.demoView.center = originalCenter
                
            })
            
        }, completion: nil)
        
    }
    
    override func viewDidAppear(_ animated: Bool) {
        planeDepart()
    }
}

let vc = MainViewController()
let nav = UINavigationController(rootViewController: vc)
PlaygroundPage.current.liveView = nav

RESULT:

ezgif com-resize

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].