I am developing a commerce application. When I add an item to the shopping cart, I want to create an effect where an image of the item follows a curved path and ends up at the cart tab.
How can I create an animation of an image along a curve like this?
The way to animate along CGPath using
UIView.animateKeyframes
(Swift 4)File:
Math.Easing.swift
File:
Math.BezierPath.swift
. Look on this SO answer: https://stackoverflow.com/a/50782971/1418981Swift 4 version similar to ObjC example from original response.
You can animate a UIView's center property using a CAKeyframeAnimation. See the CoreAnimation programming guide.
To expand upon what Nikolai said, the best way to handle this is to use Core Animation to animate the motion of the image or view along a Bezier path. This is accomplished using a CAKeyframeAnimation. For example, I've used the following code to animate an image of a view into an icon to indicate saving (as can be seen in the video for this application):
First of all import QuartzCore header file
#import <QuartzCore/QuartzCore.h>