title: Swift-幀動(dòng)畫
date: 2016-07-05 15:26:24
categories:
- Code
- iOS
tags: - UIImageView animationImages
利用一組圖片來實(shí)現(xiàn)動(dòng)畫效果膀估,這里在項(xiàng)目中需要一個(gè)LoadingView汁蝶,自定義了一個(gè)UIImageView伏钠,使用這個(gè)只需在需要的位置創(chuàng)建這個(gè)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)
})