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
4
votes
1 answer

Use of unresolved identifier 'kCAFillModeForwards'

When I try to set animation.fillMode = kCAFillModeForwards Xcode can't compile and display an error. "Use of unresolved identifier 'kCAFillModeForwards'". I've already used this in previous projects without any issues, did somebody already…
Julien
  • 159
  • 2
  • 16
4
votes
3 answers

Rotate NSImageView at its Center to Make it Spin

Swift 4, macOS 10.13 I have read a variety of answers on SO and still can't get an NSImageView to spin at its center instead of one of its corners. Right now, the image looks like this (video): http://d.pr/v/kwiuwS Here is my code: //`loader` is an…
Clifton Labrum
  • 13,053
  • 9
  • 65
  • 128
4
votes
2 answers

iPhone: Synchronize animations on two different layers

I need to synchronize a path animation on two different layers (one is used as a mask for another layer, the other shows a graphical element that follows the path, i.e. draws the mask). If I just set them up identically, they never quite do the same…
Joseph Tura
  • 6,290
  • 8
  • 47
  • 73
4
votes
3 answers

CABasicAnimation not scaling around center

I want to perform opacity And Scale effect at same time my animation work perfect but it's position is not proper. i want to perform animation on center. This is my code. btn.backgroundColor = UIColor.yellowColor() let stroke = …
jignesh Vadadoriya
  • 3,244
  • 3
  • 18
  • 29
4
votes
1 answer

CABasicAnimation creates empty default value copy of CALayer

I have a custom CALayer that draws radial gradients. It works great except during animation. It seems that each iteration of CABasicAnimation creates a new copy of the CALayer subclass with empty, default values for the properties: In the…
4
votes
0 answers

CALayer disappears after playing a CABasicAnimation backwards

I have a CALayer and I've added a CABasicAnimation to it like this: circle = CALayer() circle.frame = CGRect(x: 0, y: 0, width: 100, height: 100) circle.backgroundColor = UIColor.green().cgColor circle.cornerRadius = 50 circle.speed =…
Viktor Simkó
  • 2,607
  • 16
  • 22
4
votes
1 answer

How Can I accelerate/Slow down the rotation of a button in CABasicAnimation

I want my planet to accelerate its motion when it is closer to the sun and slow down when it is farther away from the sun.. Please help me! Thank you CABasicAnimation*…
aman hafez
  • 87
  • 1
  • 7
4
votes
3 answers

UIBezierPath + CAShapeLayer - animate a circle filling up

I am trying to animate the paths of a CAShapeLayer so that I get the effect of a circle "filling" up to a specific amount. The Issue It "works", but is not AS smooth as I think it could be, and I want to introduce some easing to it. But because I'm…
Alex
  • 5,298
  • 4
  • 29
  • 34
4
votes
1 answer

Animating CALayer background color and update model value

I want to animate a backgroundColor change for a sublayer in my UIView (on tintColorDidChange). I need to animate from the layer's current background colour to the new tint colour several times (different tint colours each time), so the model value…
alexkent
  • 1,556
  • 11
  • 25
4
votes
1 answer

CABasicAnimation seemingly performing two animations

The small scale animation works as expected but the scale animation to return to the normal size does something weird; it does the animation to the normal scale right but then it does the same animation again but a lot faster. Here is my code: func…
Petri
  • 1,020
  • 3
  • 14
  • 24
4
votes
1 answer

CABasicAnimation with keypath "bounds" not working

I have the following code to animation bounds property of CALayer using CABasicAnimation. But the code doesn't seem to work. let fromValue = textLabel.layer.bounds let toValue = CGRectMake(textLabel.layer.bounds.origin.x,…
KSC
  • 406
  • 1
  • 6
  • 8
4
votes
1 answer

Add a text layer to video at specific time

I want to add a text layer to a video for the last 4 seconds of the video. This is what i have so far: // 1 - Set up the watermark text layer CATextLayer *waterMarkText = [[CATextLayer alloc] init]; [waterMarkText…
Kaitis
  • 628
  • 9
  • 21
4
votes
2 answers

Custom circular transition between two views

I want to create an animation similar to the animation for changing inbetween different views in the Spy Mouse app. See this video for reference: http://www.youtube.com/watch?v=ylFdl7W3Srw I am unable to do the same. My animation shows a…
Alfa
  • 975
  • 7
  • 15
4
votes
1 answer

CABasicAnimation on strokeEnd

I have a CAShapeLayer in form of a square and I set the width to be 2.0f. I would like to animate its strokeEnd and for that I use a CABasicAnimation like so: CABasicAnimation *stroke = [CABasicAnimation…
Unheilig
  • 16,196
  • 193
  • 68
  • 98
4
votes
1 answer

CAShapeLayer LineCap not proper at end of CABasic Animation

I have implemented a basic line drawing animation for a progress bar.The line has a round cap edge.When I animated the line drawing the beginning of line is having a rounded cap but in the end its a square. below is the code I am using am i missing…
Karthik_S
  • 119
  • 1
  • 8