如何在swift中为UIBezierPath的点设置动画

时间:2016-04-21 12:23:11

标签: xcode swift animation shape cgpoint

我有以下代码来绘制自定义形状。但我想基于一个值为这个形状的点设置动画,在这种情况下,该值称为movementX或movementY。所以每当我调用函数shapeVoid时,我希望点基于运动值在特定方向上移动。我该怎么做呢?看下面的代码:

class ViewController: UIViewController {    

var movementX: CGFloat = 0.0
var movementY: CGFloat = 2.2


override func viewDidLoad() {
    super.viewDidLoad()


    movementUpdate = NSTimer.scheduledTimerWithTimeInterval(0.5, target: self, selector: Selector("ShapeVoid"), userInfo: nil, repeats: true)

}


func ShapeVoid(){
    view.layer.addSublayer(shape)
    shape.fillColor = UIColor(red: 255/255, green: 120/255, blue: 200/255, alpha: aValue).CGColor
    shape.lineWidth = 2
    shape.strokeColor = UIColor.blackColor().CGColor

    let shapePath = UIBezierPath()

我想为我的形状路径的点设置动画。看到下面我添加了一个名为movementX / movmentY的值来移动点,但这并没有做任何事情。我将如何为路径的点设置动画?

    shapePath.moveToPoint(CGPointMake(200, 200))
    shapePath.addLineToPoint(CGPointMake(230 + movementX, 250 + movementY))
    shapePath.addLineToPoint(CGPointMake(150 + movementX, 300 + movementY))
    shapePath.addLineToPoint(CGPointMake(100 + movementX, 280 + movementY))
    shapePath.closePath()
    shape.path = shapePath.CGPath
}
}

先谢谢,如果有什么不清楚,请告诉我。)

0 个答案:

没有答案