专业java、php、iOS、C++、网页设计、平面设计、网络营销、游戏开发、前端与移动开发培训机构
首页动画
- 使用
核心动画
来做转轮的旋转keypath
有哪些值可以设置,可以查看文档搜索CALayer Animatable Properties
,CATransform3D Key Paths
在
HMVisitorView.swift
里面添加startRotationAnimation
来做转轮旋转动画/// 旋转动画 func startRotationAnimation() { let animation = CABasicAnimation(keyPath: "transform.rotation") animation.toValue = 2 * M_PI animation.duration = 20 animation.repeatCount = MAXFLOAT iconView.layer.addAnimation(animation, forKey: "homeRotation") }
在
HMBaseViewController
的setupVisitorView
中增加如下代码,如果是首页就开始动画// 判断当前是哪个控制器 if self is HMHomeViewController { visitorView.startRotationAnimation() } else if self is HMMessageViewController { visitorView.setupVisitorInfo(imageName: "visitordiscover_image_message", message: "登录后,别人评论你的微博,发给你的消息,都会在这里收到通知") } else if self is HMDiscoveryViewController { visitorView.setupVisitorInfo(imageName: "visitordiscover_image_message", message: "登录后,最新、最热微博尽在掌握,不再会与实事潮流擦肩而过") } else if self is HMProfileViewController { visitorView.setupVisitorInfo(imageName: "visitordiscover_image_profile", message: "登录后,你的微博、相册、个人资料会显示在这里,展示给别人") }
发现切换到其他界面在切换回来动画就停止了,需要加上
animation.removedOnCompletion = false
/// 旋转动画 func startRotationAnimation() { let animation = CABasicAnimation(keyPath: "transform.rotation") animation.toValue = 2 * M_PI animation.duration = 20 animation.repeatCount = MAXFLOAT // 要加上这句,不然切换到其他tabBar或者退出到桌面在切回来动画就停止了 animation.removedOnCompletion = false iconView.layer.addAnimation(animation, forKey: "homeRotation") }