Sunday, November 20, 2016

Animation in iPhone


I had added added Animation with five images . 
Observe carefully the output. 
It's only the matter of coordinates arrangements and property settings.

Just Follow these steps  
1. Create Project
2. Take five ImageView on Layout
3. Create Image View References in ViewController
4. Observe the output carefully

A. Code is as 

import UIKit
class ViewController: UIViewController {
    @IBOutlet var img1: UIImageView!
    @IBOutlet var img2: UIImageView!
    @IBOutlet var img3: UIImageView!
    @IBOutlet var img4: UIImageView!
    @IBOutlet var img5: UIImageView!
    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, 
           typically from a nib.
    }
   
    override func viewDidLayoutSubviews() 
       // This function invoked before Layout become Visible 
    {
        img1.center = CGPointMake(img1.center.x ,     
                     img1.center.y + 1200// Bottom to Top
        img2.center = CGPointMake(img2.center.x - 400
                      img2.center.y// Left to Right
        img3.center = CGPointMake(img3.center.x + 600
                      img3.center.y )   // Right to Left
        img4.center = CGPointMake(img4.center.x
                      img4.center.y - 400) // Top to Bottom
        img5.alpha = 0 ;     // Disappear
    }
    
    override func viewDidAppear(animated: Bool
      // Just invoke after App Launched 
   {
        
  UIView.animateWithDuration(2// Animation Duration 2 secs
        {
        self.img1.centerCGPointMake(self.img1.center.x
                            self.img1.center.y - 1200 )
        self.img2.centerCGPointMake(self.img2.center.x
                            400 , self.img2.center.y  )
        self.img3.centerCGPointMake(self.img3.center.x
                            600 , self.img3.center.y  )
        self.img4.centerCGPointMake(self.img4.center.x
                            self.img4.center.y + 400 )
        self.img5.alpha = 1 ;
        }
    }

}



B. Output is as after 2 second of App launched



No comments:

Post a Comment