Swift-帧动画


title: Swift-帧动画
date: 2016-07-05 15:26:24
categories:

  • Code
  • iOS
    tags:
  • UIImageView animationImages


利用一组图片来实现动画效果,这里在项目中需要一个LoadingView,自定义了一个UIImageView,使用这个只需在需要的位置创建这个UIImageView即可。在这把自定义UIImageView类全部代码分享给大家


//
//  FMLoadingImageViw.swift
//  test
//
//  Created by Xinxibin on 16/7/5.
//  Copyright © 2016年 GloryMan. All rights reserved.
//

import UIKit

class FMLoadingImageViw: UIImageView {
    
    
    private var images:[UIImage] = []
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        self.frame = frame
        setData()
    }
    
    func setData() {
        for item in 0..<6 {
            images.append(UIImage(named: "С_0000\(item)")!)
        }
        self.backgroundColor = UIColor.clearColor()
    }
    
    func showLoadingView() {
        
        self.animationImages = images
        self.animationDuration = 0.25
        self.animationRepeatCount = 0
        self.startAnimating()
        UIView.animateWithDuration(0.25) {
            self.alpha = 1
        }
    }
    
    func hiden() {
        
        UIView.animateWithDuration(0.25, animations: {
            self.alpha = 0
        }) { (bool) in
            self.stopAnimating()
        }
    }
    
    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
    }
    
}

    // 使用方法

    indector = FMLoadingImageViw(frame: CGRect(x: 0, y: 0, w: indectorWith, h: indectorHeight))
    self.addSubview(indector!)
        
    // 使用SnapKit添加约束
    indector?.snp_makeConstraints(closure: { (make) in
        make.centerX.equalTo(self.snp_centerX)
        make.centerY.equalTo(self.snp_centerY)
    })


你可能感兴趣的:(Swift-帧动画)