Questions tagged [cabasicanimation]

"CABasicAnimation" is the most basic explicit animation in Core Animation. By simply specifying a "from" value, a "to" value and optionally other parameters like the duration you can have hardware accelerated animations in just a few lines of code.

CABasicAnimation is the most basic explicit animation in Core Animation (). By simply specifying a from value, a to value and optionally other parameters like the duration you can have hardware accelerated animations in just a few lines of code.

Animations are created with the key path that they should be animating like

CABasicAnimation *moveAnimation = 
↪   [CABasicAnimation animationWithKeyPath:@"position"];

After creating a new animation it is configured. Common configurations include setting the values to animate to and from, setting a duration and changing the timing function (how the animation is animated). Note that Core Graphics values have to be wrapped into NSValue objects when used.

// valueWithCGPoint: for iOS and valueWithPoint: for OS X.
[moveAnimation setFromValue:[NSValue valueWithCGPoint:myStartPoint]]; 
[moveAnimation setToValue:[NSValue valueWithCGPoint:myEndPoint]]; 
[moveAnimation setDuration:3.0]; // 3 seconds
[moveAnimation setTimingFunction:
↪   [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];

When the animation is configured it is applied by adding it to the layer that should animate. Note that the key parameter when adding the animation has nothing to do with the key path of the animation. It is only used to reference the animation after is has been added to the layer.

[myLayer addAnimation:moveAnimation 
               forKey:@"myMoveAnimation"];

Note that explicitly animating a property like this doesn't change the value of the actual property and after the animation finishes it will remove itself and the layer will jump back to the state it had before the animation. To also change the value of the property, explicitly change the value in the same before or after adding the animation to the layer.

One powerful feature even custom properties can be animated the same way (by specifying the key path).

Basic animations is available on both (since iOS 2.0) and (since OS X 10.5 "Leopard") and is part of the framework.

602 questions
9
votes
5 answers

How to animate borderColor change in swift

For some reason this isn't working for me: let color = CABasicAnimation(keyPath: "borderColor") color.fromValue = sender.layer.borderColor; color.toValue = UIColor.redColor().CGColor; color.duration = 2; color.repeatCount =…
Chase Roberts
  • 9,082
  • 13
  • 73
  • 131
9
votes
5 answers

How do I animate opacity using swift?

Could someone please provide me with an example of animating the opacity of an Image View in swift?? I couldn't even find a good example in objective c func showCorrectImage(element: AnyObject){ var animation : CABasicAnimation =…
PugLvr28
  • 111
  • 1
  • 1
  • 6
9
votes
1 answer

CABasicAnimation start from current layer position

This is my second week of Obj-C programming and I'm facing a little problem with animating. I use this animation: CABasicAnimation *fullRotation = [CABasicAnimation animationWithKeyPath:@"transform.rotation"]; fullRotation.toValue = [NSNumber…
Joseph
  • 149
  • 1
  • 2
  • 7
9
votes
3 answers

CABasicAnimation to make NSView flip

I'm making a card game for mac and I'm using a CABasicAnimation to making the card flip around. It's almost working, but it could be a bit better. As it works now, the card flips inwards (to the left) - Screenshot 1. When the card has moved…
Holger Sindbaek
  • 2,278
  • 6
  • 41
  • 68
9
votes
3 answers

Animated AnnotationView disappears while zooming the mapview?

I add a CABasicAnimation to the AnnotationView layer to simulate a car moving on the mapview. This works fine until I try to zoom in or out the mapview when the animation is in progress. I found the animating annotation view disappears when zooming…
8
votes
2 answers

CAShapeLayer Animating Path Glitches / Flickers (From Ellipse to Rect and back)

I am running into an issue when I create an explicit animation to change the value of a CAShapeLayer's path from an ellipse to a rect. In my canvas controller I setup a basic CAShapeLayer and add it to the root view's layer: CAShapeLayer…
C4 - Travis
  • 4,502
  • 4
  • 31
  • 56
8
votes
1 answer

when to use CABasicAnimation and CAKeyFrameAnimation and CGAffineTransform?

when to use CABasicAnimation and CAKeyFrameAnimation and CGAffineTransform?
RK-
  • 12,099
  • 23
  • 89
  • 155
8
votes
2 answers

CABasicAnimation delay between repeat

The code below creates a "shimmer" effect and works great. (The look of reflected light moving across a glossy surface.) It's currently set to repeat forever which is fine, however, I'd like there to be a pause between each shimmer. I can delay the…
squarehippo10
  • 1,855
  • 1
  • 15
  • 45
8
votes
1 answer

CATransform3D Key Paths with #keyPath

Is it possible to use enhanced key path (as described here) for a CATransform3D property in Swift 3 with new #keyPath keyword? In other words to replace let scaleAnimation = CABasicAnimation(keyPath: "transform.scale") with something like let…
Radek
  • 581
  • 4
  • 12
8
votes
1 answer

how to replace panGestureDidMove with fixed start to end position

I have been using UIPanGestureRecognizer to recognise touches but I want to replace it with a fixed start to end position for my animation. Please see the code below: panGestureDidMove: func panGestureDidMove(gesture: UIPanGestureRecognizer) { if…
Jickery
  • 237
  • 4
  • 15
8
votes
1 answer

How to set a color for CABasicAnimation?

CABasicAnimation has the toValue property which expects an id. But Quartz Core doesn't work with UIColor, it wants a CGColor struct instead. How would I supply a color to a CABasicAnimation?
Proud Member
  • 40,078
  • 47
  • 146
  • 231
8
votes
1 answer

CABasicAnimation how to get current angle of rotation

I have some problem with CABasicAnimation. It`s similar to that post: CABasicAnimation rotate returns to original position So, i have uiimageview that rotate in touchMove. In touchEnd invoke method that do "animation of inertia"…
frankWhite
  • 1,523
  • 15
  • 21
7
votes
1 answer

Animation of stroke of circle segment ends in complete stroke

I'm trying to animate the appearance of a segment of a circle. To archive this I use a CABasicAnimations which works quiet fine. The animation starts on top and moves quiet nicely to one third of the whole circle. But when the animation finishes,…
Shingoo
  • 826
  • 10
  • 26
7
votes
2 answers

CABasicAnimation change duration/speed during rotation

I am using CABasicAnimation to rotate forever an imageView and I want to change rotation speed during rotation. Can anybody help me with this? Thanks in advance!
leon4ic
  • 339
  • 4
  • 12
7
votes
1 answer

Animate a CAShapeLayer circle into a rounded-corner triangle

I'd like to animate a shape as it transitions from a circle to a rounded-corner triangle. TL;DR: How do I animate a CAShapeLayer's path between two CGPath shapes? I know that they need to have the same number of control points, but I think I'm doing…
bryanjclark
  • 6,247
  • 2
  • 35
  • 68
1 2
3
40 41