ui控件之UIImageView(imageView的动画效果)

来源:互联网 发布:linux查看文件命令 编辑:程序博客网 时间:2024/06/05 15:58

//  Created by Catherine on 2017/8/28.

//  Copyright © 2017 Catherine. All rights reserved.

//


import UIKit


class ViewController: UIViewController {


    overridefunc viewDidLoad() {

        super.viewDidLoad()

        // Do any additional setup after loading the view, typically from a nib.

        //创建一个imageView

        let imageView:UIImageView =UIImageView(frame: CGRect(x: 100, y:100, width: 100, height:100))

        //imageView设置图片

        imageView.image =UIImage(named: "pig1.png")

        //设置imageView的背景颜色

        imageView.backgroundColor =UIColor.gray

        //设置imageView的高亮图片

        imageView.highlightedImage =UIImage(named: "pig2.png")

        //设置imageView为高亮状态(才能显示上图)

        //imageView.isHighlighted = true

        //设置imageView的动画效果(播放一组图片)

        //创建一个数组

        var array:Array<UIImage?> =Array()

        for iin 1  ..<5  {

            let image:UIImage? =UIImage(named: String(format:"pig%d.png", i))

            array.append(image!)

        }

        //设置imageView的动画数组

        imageView.animationImages = arrayas? [UIImage]

        //设置播放的次数 0是循环播放

        imageView.animationRepeatCount =0

        //设置播放一轮的时间

        imageView.animationDuration =1.5

        //开始播放动画

        imageView.startAnimating()

        

        self.view.addSubview(imageView)

        

    }


    overridefunc didReceiveMemoryWarning() {

        super.didReceiveMemoryWarning()

        // Dispose of any resources that can be recreated.

    }



}