Moving and animating UIImageView with fast

I have a question that should be fairly simple. Basically, I am trying to move an object (UIImageView) from point A (where it is installed in the storyboard) to point B, which I define programmatically.

My first pass through this led to this code

        UIView.animateWithDuration(0.75, delay: 0.5, options: UIViewAnimationOptions.CurveLinear, animations: {
            self.signInButton.alpha = 1
            self.signInButton.center.y = 10
        }, completion: nil)

However, what this code does is basically move the offcenter button and then back to its original location.

Then I looked in QuartzCore to help me, but everything in Objective-C. I have this method:

    func moveImage(view: UIImageView){
        var toPoint: CGPoint = CGPointMake(0.0, -10.0)
        var fromPoint : CGPoint = CGPointZero

        var movement = CABasicAnimation(keyPath: "movement")
        movement.additive = true
        movement.fromValue = fromPoint
        movement.toValue = toPoint
        movement.duration = 0.3

        view.layer.addAnimation(movement, forKey: "move")
    }

However, the problem here is that movement.fromValueit cannot accept CGPoint. I know that there was a function in the C object that converts a CGPointto NSValue, however this function does not seem to be recommended from Swift, and I cannot find another way to do this.

, CGPoint NSValue, moveImage() , A B?

!

UIImage UIImageView ( ) Loop

+4
2

NSValue(CGPoint: cgpiont) NSValue.valueWithCGPoint(<#point: CGPoint#>), QuickTime. NSValue(CGPoint: cgpiont) - , , CGPoint NSValue swift.Flowing

func moveImage(view: UIImageView){
    var toPoint: CGPoint = CGPointMake(0.0, -10.0)
    var fromPoint : CGPoint = CGPointZero

    var movement = CABasicAnimation(keyPath: "movement")
    movement.additive = true
    movement.fromValue =  NSValue(CGPoint: fromPoint)
    movement.toValue =  NSValue(CGPoint: toPoint)
    movement.duration = 0.3

    view.layer.addAnimation(movement, forKey: "move")
}
+11

SWIFT 3

 func moveImageView(imgView: UIImageView){
        var toPoint:CGPoint = CGPoint(x: 0.0, y: -10.0)
        var fromPoint:CGPoint = CGPoint.zero
        var movement = CABasicAnimation(keyPath: "movement")
        movement.isAdditive = true
        movement.fromValue = NSValue(cgPoint: fromPoint)
        movement.toValue = NSValue(cgPoint: toPoint)
        movement.duration = 0.3
        imgView.layer.add(movement, forKey: "move")
    }
+3

All Articles