测试已测试 | ✗ |
语言语言 | SwiftSwift |
许可证 | MIT |
发布最新发布 | 2017年2月 |
SwiftSwift 版本 | 3.0.1 |
SPM支持 SPM | ✗ |
由 Alvin Zhu 维护。
Morph 使用更优雅的语法包装 CoreAnimation,帮助您构建出令人惊叹的动画(Objective-C 版本)。
要实现上述图层效果,您只需编写以下代码
// Radiation
radiation.mr_startAnimations({ (animate) in
animate.opacity.from(1).to(0).animate(duration)
animate.scale.from(1).to(0).animate(duration)
animate.center.from(fromPoint).to(toPoint).animate(duration)
}, completion: {
radiation.removeFromSuperlayer()
})
// Background circle
circle.mr_startAnimations({ (animate) in
animate.scale.by([0.8, scale, scale]).during([0, 0.5, 1.0]).animate(duration)
animate.opacity.from(0.5).to(0).animate(duration)
}, completion: {
circle.removeFromSuperlayer()
})
查看 Morph iOS 示例 以获取更多信息。
// Compose your animations in here.
view.mr_startAnimations({ (animate) in
animate.x.to(100).animate(1)
animate.backgroundColor
.to(UIColor.red).after(0.4)
.delay(0.2).to(UIColor.yellow).animate(0.4)
})
属性 | keyPath |
---|---|
bounds | bounds |
size | bounds.size |
origin | position |
center | position |
x | position.x |
y | position.y |
width | bounds.size.width |
height | bounds.size.height |
opacity | opacity |
backgroundColor | backgroundColor |
borderColor | borderColor |
borderWidth | borderWidth |
cornerRadius | cornerRadius |
anchor | anchorPoint |
path | position |
属性 | keyPath | 描述 |
---|---|---|
scale | transform.scale | 幂等 |
scaleX | transform.scale.x | 幂等 |
scaleY | transform.scale.y | 幂等 |
rotateX | transform.rotation.x | 接受度值。幂等 |
rotateY | transform.rotation.y | 接受度值。幂等 |
rotateZ | transform.rotation.z | 接受度值。幂等 |
rotate | transform.rotation.z | 与 rotateZ 相同 |
xOffset | position.x | 通过指定值增加或减少原点的 x 坐标 |
yOffset | position.y | 通过指定值增加或减少原点的 y 坐标 |
heightOffset | bounds.size.width | 通过指定值增加或减少宽度 |
widthOffset | bounds.size.height | 通过指定值增加或减少高度 |
rotateOnPath | position | 沿着路径动画使旋转与路径切线匹配 |
reverseRotateOnPath | position | 沿着路径动画使旋转与路径切线匹配并自动反转 |
fillColor | fillColor | CAShapeLayer 仅支持 |
strokeColor | strokeColor | CAShapeLayer 仅支持 |
strokeStart | strokeStart | CAShapeLayer 仅支持 |
strokeEnd | strokeEnd | CAShapeLayer 仅支持 |
lineWidth | lineWidth | CAShapeLayer 仅支持 |
miterLimit | miterLimit | CAShapeLayer 仅支持 |
lineDashPhase | lineDashPhase | CAShapeLayer 仅支持 |
属性应该以 animate(duration) 函数结束。
animate.width.to(100).animate(1.0)
要链接不同时间具有不同值的属性,可以调用 after(duration) 函数。
animate.x.to(50).after(1.0).to(200).animate(2.0)
要延迟动画,请调用 delay(duration) 函数。
// it will disappear in one second and appear again after two second delay
animate.opacity
.to(0.0).after(1.0)
.delay(2.0).to(1.0).animate(1.0)
可以使用 repeat(times)、repeatInfinity() 和 autoreverse() 函数重复或自动反转动画。
以下是如何设置值和关键时间,就像 CAKeyframeAnimation 一样的示例。
animate.scale
.by([0.8, 1, 1])
.during([0, 0.5, 1.0])
.animate(duration)
/* the same as:
CAKeyframeAnimation *keyframeAnimation = [CAKeyframeAnimation animationWithKeyPath:@"transform.scale"];
keyframeAnimation.values = @[ @0.0, @1.1, @1.0 ];
keyframeAnimation.keyTimes = @[ @0.0, @0.5, @1.0 ];
keyframeAnimation.duration = duration;
*/
将 logEnable
设置为 true
将会打印动画详细信息,以供调试。
animate.logEnable = true
感谢他们的出色工作!
Morph 可在 MIT 许可证下使用。更多信息请参阅 LICENSE 文件。