一个Loading动画

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()

戳我看项目源码:LoadingIndicator

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 177,131评论 25 709
  • 发现 关注 消息 iOS 第三方库、插件、知名博客总结 作者大灰狼的小绵羊哥哥关注 2017.06.26 09:4...
    肇东周阅读 14,797评论 4 61
  • 今日独胆5 双胆56 关注356 五码13569 六码134569
    情敌贝多芬阅读 1,085评论 0 0
  • 岁岁重阳节,今年何有别? 黄花笼远烟,不见雨中辙。
    A_master阅读 2,286评论 1 7
  • 有些地方不尽完美,却还会故地重游,凤凰就是这样的地方。我去过乌镇,去过西塘,去过芙蓉镇,却只想念凤凰。中国...
    啊咧君阅读 4,237评论 2 3

友情链接更多精彩内容