//
// HomeViewController.swift
// Viking
//
// Created by 雪衣侯 on 2020/7/24.
// Copyright © 2020 雪衣侯. All rights reserved.
//
import UIKit
class HomeViewController: BaseViewController {
lazy var vm: HomeViewModel = HomeViewModel(self)
lazy var v: HomeView = HomeView(frame: CGRect.zero, vm: self.vm)
override func viewDidLoad() {
super.viewDidLoad()
self.view.backgroundColor = .systemBlue
shapeLayer.add(animationGroup, forKey: "animationGroup")
heartImgView.layer.add(setUpAnimation(), forKey: "scale")
rotaImgView.layer.add(rotationAnimation(), forKey: "rotationAnimation")
}
override func ai_setupViews() {
view.addSubview(v)
view.addSubview(bgView)
bgView.layer.addSublayer(replicatorLayer)
replicatorLayer.addSublayer(shapeLayer)
replicatorLayer.addSublayer(rotaImgView.layer)
replicatorLayer.addSublayer(heartImgView.layer)
view.addSubview(rotaImgView)
view.addSubview(heartImgView)
}
override func ai_setupLayout() {
v.snp.makeConstraints{(make) in
make.edges.equalToSuperview()
}
bgView.snp.makeConstraints{(make) in
make.edges.equalToSuperview()
}
rotaImgView.snp.makeConstraints{(make) in
make.width.height.equalTo(120)
make.centerX.equalToSuperview()
make.centerY.equalToSuperview()
}
heartImgView.snp.makeConstraints{(make) in
make.width.height.equalTo(60)
make.centerX.equalToSuperview()
make.centerY.equalToSuperview()
}
}
lazy var bgView: UIImageView = {
let new = UIImageView()
new.image = UIImage(named: "heart_bg")
return new
}()
lazy var heartImgView: UIImageView = {
let new = UIImageView()
new.image = UIImage(named: "heart")
return new
}()
lazy var rotaImgView: UIImageView = {
let new = UIImageView()
new.image = UIImage(named: "online_black_circle")
return new
}()
let shapeLayer: CAShapeLayer = {
let shapeLayer = CAShapeLayer()
shapeLayer.frame = CGRect(x: (UIScreen.main.bounds.width-400)/2, y: (UIScreen.main.bounds.height-400)/2, width: 400, height: 400)
shapeLayer.path = UIBezierPath(ovalIn: CGRect(x: 0, y: 0, width: 400, height: 400)).cgPath
shapeLayer.fillColor = UIColor(red: 198 / 255.0, green: 201 / 255.0, blue: 220 / 255.0, alpha: 1.0).cgColor //蓝色
shapeLayer.opacity = 0.0
return shapeLayer
}()
lazy var replicatorLayer: CAReplicatorLayer = {
let replicatorLayer = CAReplicatorLayer()
replicatorLayer.frame = CGRect(x: 0, y: 0, width: 400, height: 400)
replicatorLayer.instanceDelay = 0.4
replicatorLayer.instanceCount = 3
replicatorLayer.addSublayer(shapeLayer)
return replicatorLayer
}()
lazy var animationGroup: CAAnimationGroup = {
let animationGroup = CAAnimationGroup()
animationGroup.animations = [alphaAnimation(), scaleAnimation()]
animationGroup.duration = 1.5
animationGroup.autoreverses = false
animationGroup.repeatCount = MAXFLOAT
animationGroup.isRemovedOnCompletion = false
return animationGroup
}()
// func alphaAnimation() -> CABasicAnimation {
// let alpha = CABasicAnimation(keyPath: "opacity")
// alpha.fromValue = NSNumber(value: 1.0)
// alpha.toValue = NSNumber(value: 0.0)
// return alpha
// }
// func scaleAnimation() -> CABasicAnimation{
// let scale = CABasicAnimation(keyPath: "transform")
// scale.fromValue = NSValue(caTransform3D: CATransform3DScale(CATransform3DIdentity, 0.0, 0.0, 0.0))
// scale.toValue = NSValue(caTransform3D: CATransform3DScale(CATransform3DIdentity, 1.5, 1.5, 0.0))
// return scale
// }
//波浪放大动画
func scaleAnimation() -> CABasicAnimation {
let animation = CABasicAnimation(keyPath: "transform.scale.xy")
animation.fromValue = NSNumber(value: 0)
animation.toValue = NSNumber(value: 1)
return animation
}
//波浪透明度动画
func alphaAnimation() -> CAKeyframeAnimation {
let animation = CAKeyframeAnimation(keyPath: "opacity")
animation.values = [0.4,0.6,0]
animation.keyTimes = [0,0.4,1] //第一个时间值必须为0,列表中的最后一个时间值必须为1
return animation
}
//心跳动画
func setUpAnimation() -> CABasicAnimation{
let scalAnima = CABasicAnimation(keyPath: "transform.scale.xy")
scalAnima.fromValue = NSNumber(value:1)
scalAnima.toValue = NSNumber(value:1.6)
scalAnima.duration = 0.2
scalAnima.autoreverses = true
scalAnima.repeatCount = MAXFLOAT
scalAnima.isRemovedOnCompletion = false
return scalAnima
}
//扇形旋转动画
func rotationAnimation() -> CABasicAnimation{
let rotationAnimation = CABasicAnimation(keyPath: "transform.rotation.z")
rotationAnimation.toValue = Double.pi * 2
rotationAnimation.duration = 0.6
rotationAnimation.isCumulative = true
rotationAnimation.repeatCount = MAXFLOAT
rotationAnimation.isRemovedOnCompletion = false
return rotationAnimation
}
}
animation
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
推荐阅读更多精彩内容
- 还可以参考这篇:http://www.cnblogs.com/shenfangfang/p/5713564.htm...
- 概念 Dopesheet 上一次说到我们可以通过Animation窗口创建Animation Clip,其中比较重...
- View Animation 你可以使用视图动画系统在视图上执行补间动画。Tween动画使用诸如动画的起始点,终点...
- 本系列文档参考苹果官文:Core Animation Programming Guide还包括下面一系列文章: C...
- 000 属性动画简介 属性动画是 Android API level 11(Android 3.0)中添加的动画框...