2016年8月1日 星期一

Mac Swift Animation 1

Ref:https://www.codementor.io/swift/tutorial/view-animations-ios-tutorial
1. Open a new SingleView project
2. Open Main.storyboard
    Add ImageView Control
3. Open Assets.xcassets
     Right button click : Add new image set
     Drop Image file
4. Add ImageView (image)
5. Add animation function in ViewController.swift
//
//  ViewController.swift
//  SWANPNG1
//
//  Created by Jou CS on 2016/8/1.
//  Copyright © 2016 Jou CS. All rights reserved.
//

import UIKit

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
// 1. drag ImageView control into here : declare (MVC)
    @IBOutlet weak var vIMG1: UIImageView!
    
// 2. Override function of viewWillAppear    
    override func viewWillAppear(animated: Bool) {
        super.viewWillAppear(animated)
        
    }
// 3. Override function of viewDidAppear
    
    override func viewDidAppear(animated: Bool) {
        super.viewDidAppear(animated)
        UIView.animateWithDuration(5, animations: {
            self.vIMG1.backgroundColor = UIColor.blueColor();
        })
        
    }


}






 











4. Repeat, Autoreverse
 //UIView.animateWithDuration(5, animations: {
 //    self.vIMG1.backgroundColor = UIColor.blueColor();
 // })

 UIView.animateWithDuration(5, delay: 0.5, options: [.Repeat, .Autoreverse], animations:{ self.vIMG1.backgroundColor = UIColor.blueColor();}, completion: nil)


沒有留言:

張貼留言