JiongXing / LoadingIndicator

加载动画 Loading Animation

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

LoadingIndicator

LoadingIndicator.gif

这种魔术般的效果是怎么做到的?用简单的UIView动画即可:

    /// 缩小
    private func scaleToSmall() {
        guard isAnimatedEnable else {
            return
        }
        isAnimating = true
        self.contentView.snp.updateConstraints { (make) in
            make.width.height.equalTo(self.dotRadius * 2)
        }
        UIView.animate(withDuration: animationDuration / 2, animations: {
            self.contentView.layoutIfNeeded()
            self.contentView.transform = CGAffineTransform(rotationAngle: CGFloat.pi)
        }) { (_) in
            self.isAnimating = false
            self.scaleToLarge()
            if self.isAnimatedEnable == false {
                self.prepareToAnimate()
            }
        }
    }
    
    /// 放大
    private func scaleToLarge() {
        guard isAnimatedEnable else {
            return
        }
        isAnimating = true
        self.contentView.snp.updateConstraints { (make) in
            make.width.height.equalTo(self.sideLength)
        }
        UIView.animate(withDuration: animationDuration / 2, animations: {
            self.contentView.layoutIfNeeded()
            self.contentView.transform = CGAffineTransform.identity
        }) { (_) in
            self.isAnimating = false
            self.scaleToSmall()
        }
    }

使用方法:

LoadingIndicator.share.show(inView: view)
LoadingIndicator.share.dismiss()

About

加载动画 Loading Animation

License:MIT License


Languages

Language:Swift 92.3%Language:Shell 6.7%Language:Objective-C 0.7%Language:Ruby 0.2%