Ios 如何设置从一点拖动到另一点的UIImageView的平移动画?

Ios 如何设置从一点拖动到另一点的UIImageView的平移动画?,ios,swift,uiimageview,cgpath,cakeyframeanimation,Ios,Swift,Uiimageview,Cgpath,Cakeyframeanimation,我在Swift iOS应用程序中遇到一些动画问题。我试图允许用户抓取UIImageView并将其拖动到另一个点。然后,如果按下“动画”,则会沿从第一个点到第二个点的路径显示imageview的动画 这是我到目前为止所拥有的,更让我感到不安的是,我正在努力寻找一个早期的解决方案。按下“动画”按钮时出现错误,显示: CGPathAddLineToPoint(CGMutablePathRef, const CGAffineTransform *, CGFlo

我在Swift iOS应用程序中遇到一些动画问题。我试图允许用户抓取UIImageView并将其拖动到另一个点。然后,如果按下“动画”,则会沿从第一个点到第二个点的路径显示imageview的动画

这是我到目前为止所拥有的,更让我感到不安的是,我正在努力寻找一个早期的解决方案。按下“动画”按钮时出现错误,显示:

CGPathAddLineToPoint(CGMutablePathRef, const CGAffineTransform *, 
                     CGFloat, CGFloat): no current point.
这是我的密码:

// There was some global stuff set up earlier, such as pathPlayer1 which is an 
// array of CGPoints I am using to store the path; they are commented 

override func viewDidLoad() {
    super.viewDidLoad()

    var panRecognizer1 = UIPanGestureRecognizer(target: self, action: "handlePanning1:")
    playerWithBall.addGestureRecognizer(panRecognizer1)
    pathPlayer1.append(playerWithBall.center)


}

func handlePanning1(recognizer: UIPanGestureRecognizer) {

    var newTranslation: CGPoint = recognizer.translationInView(playerWithBall)

    recognizer.view?.transform = CGAffineTransformMakeTranslation(lastTranslation1.x + newTranslation.x, lastTranslation1.y + newTranslation.y)

    if recognizer.state == UIGestureRecognizerState.Ended {
        // lastTranslation1 is a global
        lastTranslation1.x += newTranslation.x
        lastTranslation1.y += newTranslation.y

        // another global to get the translation from imageview center in main view
        // to the new point in main view
        playerWithBallPos.x = playerWithBall.center.x + lastTranslation1.x
        playerWithBallPos.y = playerWithBall.center.y + lastTranslation1.y

        // add this point to the path to animate along
        pathPlayer1.append(playerWithBallPos)

        //This was to make sure the append was working
        println(pathPlayer1)

    }
}

@IBAction func animatePlay(sender: UIButton) {
    var path = CGPathCreateMutable()

    var i: Int = 0
    for (i = 0; i < pathPlayer1.count; i++) {
        var location: CGPoint! = pathPlayer1[i]

        // I think if its the first time you need to call CGPathMoveToPoint?
        if firstTime {
            CGPathMoveToPoint(path, nil, location.x, location.y)
            firstTime = false
        } else {
            CGPathAddLineToPoint(path, nil, location.x, location.y)
        }
    }

    var pathAnimation: CAKeyframeAnimation = CAKeyframeAnimation(keyPath: "pos")

    pathAnimation.path = path
    pathAnimation.duration = 1.0
}
平移效果很好,似乎正确地获得了新的点,但我没有使用objective-c的经验,也没有计算机科学课上swift/iOS的知识,我不熟悉这些类型的动画


我想让我的解决方案发挥作用,这样我就可以将它从一个单一的图像视图扩展到多个视图,并同时为每个视图设置动画想象一个运动剧本并为一个剧本设置动画或类似的东西post显示我在viewDidLoad方法中执行此操作