10
A
回答
8
可以使用核心动画和CAKeyFrameAnimation定义曲线点做到这一点。请参阅本教程:http://nachbaur.com/2011/01/07/core-animation-part-4/
-6
可以通过将动画嵌套在completion子句中来堆叠动画。
0
上方的一个可以通过achived: -
ⅰ)CAKeyframeAnimationⅱ)Create Curve Pathⅲ)动画的自定义视图
import UIKit
import CoreGraphics
class ViewController: UIViewController {
var moveAlongPath:CAAnimation!
override func viewDidLoad() {
super.viewDidLoad()
addAnimation()
initiateAnimation()
}
func curevedPath() -> UIBezierPath {
let path = createCurvePath()
let shapeLayer = CAShapeLayer()
shapeLayer.path = path.cgPath
shapeLayer.strokeColor = UIColor.blue.cgColor
shapeLayer.fillColor = UIColor.clear.cgColor
shapeLayer.lineWidth = 1.0
self.view.layer.addSublayer(shapeLayer)
return path
}
func addAnimation() {
let moveAlongPath = CAKeyframeAnimation(keyPath: "position")
moveAlongPath.path = curevedPath().cgPath
moveAlongPath.duration = 5
moveAlongPath.repeatCount = HUGE
moveAlongPath.calculationMode = kCAAnimationPaced
moveAlongPath.timingFunctions = [CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseOut)]
self.moveAlongPath = moveAlongPath
}
func initiateAnimation() {
let layer = createLayer()
layer.add(moveAlongPath, forKey: "animate along Path")
}
//MARK:- Custom View Path
func createLayer() -> CALayer {
let customView = CustomView(frame: CGRect(x: 0, y: 0, width: 50, height: 50))
self.view.addSubview(customView)
let customlayer = customView.layer
customlayer.bounds = CGRect(x: 0, y: 0, width: 50, height: 50)
customlayer.position = CGPoint(x: 25, y: 25)
return customlayer
}
//MARK:- Custom Curve Path
func createCurvePath() -> UIBezierPath {
let path = UIBezierPath()
path.move(to: CGPoint(x: 10, y: 200))
path.addQuadCurve(to: CGPoint(x: 300, y: 200), controlPoint: CGPoint(x: 150, y: 10))
return path
}
}
class CustomView:UIView {
override init(frame: CGRect) {
super.init(frame: frame)
setUpView()
}
func setUpView() {
let image = UIImage(named: "Go.png")
let imageView = UIImageView(image: image)
imageView.frame = CGRect(x: 0, y: 0, width: self.bounds.width, height: self.bounds.height)
addSubview(imageView)
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}
相关问题
- 1. iOS - 沿弯曲路径拖动对象
- 2. 沿着曲线路径在背景中移动的图像android
- 3. 沿着Bezier曲线路径的iPhone移动UI图像视图
- 4. 沿着路径在PHP中弯曲文本?
- 5. Cocos2d - 在弯曲路径中移动精灵
- 6. Cocos2d - 以不同速度在弯曲路径中移动物体
- 7. 沿路径移动形状?
- 8. QGraphicsItem沿着路径移动
- 9. 对象沿路径移动
- 10. 沿路径移动精灵
- 11. 沿预定路径移动图像?
- 12. HTML5沿路径移动图像
- 13. 聚合物弯曲运动路径
- 14. 了解如何沿着改变的路径移动路径
- 15. 沿着曲线路径放置图像
- 16. 在iOS中沿路径检测绘图
- 17. 弯曲的三角形路径?
- 18. 如何使box2d物体沿着贝塞尔曲线/圆弧路径移动
- 19. 沿着路径移动通过触摸
- 20. CAKeyframeanimation沿着路径移动UIView
- 21. Android路径弯曲/波浪线
- 22. 沿着弯曲的UIBezierPath绘制渐变
- 23. 滚动时沿路径移动背景图像的位置
- 24. SVG:如何修正Bezier弯曲路径的偏心标记?
- 25. iPhone UIImageView与动画图像需要沿着路径移动
- 26. 沿着圆形路径移动图像视图
- 27. SVG:沿曲线路径追加形状
- 28. 沿着带有Java图形的弧形路径移动形状
- 29. 沿着带有java图形的弧形路径移动物体
- 30. 如何沿着路径制作动画
层谢谢...我将检查 – 2011-04-30 05:59:02
该示例涉及动画层,而不是整个视图。我有一个案例,我需要沿着路径移动整个UIView。我可以很容易地使用animateWithDuration从这里到那里,但我看不到如何使用它从这里到那里使用给定的路径。当我尝试将一堆animateWithDuration调用串起来时,最后一次调用总是取消较早的调用。 – EFC 2011-12-30 17:18:22