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)
沒有留言:
張貼留言