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
17
votes
2 answers

replacing CALayer and CABasicAnimation with SKScene and SKActions

I am trying to restructure this Github Swift project on Metaballs so that the circles are represented by SKShapeNodes that are moved around by SKActions instead of CABasicAnimation. I am not interested in the various Metaball parameters (the…
OnlyCodeMatters
  • 683
  • 1
  • 5
  • 15
15
votes
3 answers

CABasicAnimation delegate for animationDidStop?

I am following the example at the bottom of the page to call an animationDidStop function. http://www.informit.com/articles/article.aspx?p=1168314&seqNum=2 The author says: I have an object that is designed specifically to be the delegate of…
user157733
  • 569
  • 2
  • 12
  • 26
15
votes
3 answers

Draw circle with UIBezierPath

I'm trying to draw a circle using UIBezierPath addArcWithCenter method : UIBezierPath *bezierPath = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(0., 0., 100., 100.)]; [bezierPath addArcWithCenter:center radius:0. …
Mosbah
  • 1,347
  • 1
  • 14
  • 28
14
votes
1 answer

How to stop UIView CABasicAnimation in iPhone

I have 3 views dynamically created by using for loop. in that i called the below method for rotation animation - (void)runRightSpinAnimationOnView:(UIView*)view duration:(CGFloat)duration rotations: (CGFloat)rotations repeat:(float)repeat; { …
Hari Babu
  • 891
  • 1
  • 9
  • 22
13
votes
5 answers

iOS animate/morph shape from circle to square

I try to change a circle into a square and vice versa and I am almost there. However it doesn't animates as expected. I would like all corners of a square to be animated/morphed at the same time but what I get is the following: I use CAShapeLayer…
fgeorgiew
  • 1,194
  • 2
  • 8
  • 25
13
votes
1 answer

CABasicAnimation with zero duration

I have a CALayer in an AVMutableComposition that is faded in, should stay on screen for a while and then disappear. The problem is, it should disappear without an animation, but CABasicAnimation has a minimum duration of 0.25 seconds. How would can…
Swissdude
  • 3,486
  • 3
  • 35
  • 68
12
votes
1 answer

Issue setting CABasicAnimation delegate in Swift 3?

I'm getting the following error Cannot assign value of type 'StarButton' to type 'CAAnimationDelegate?' on the last line of this CABasicAnimation block: let fillCircle = CABasicAnimation(keyPath: "opacity") fillCircle.toValue = 0 …
Jared Garcia
  • 751
  • 1
  • 8
  • 17
11
votes
4 answers

iOS: a Complete 360 Degree-Rotation Using Block, Not CABasicAnimation

It should be something really simple, but I have not been successful in getting this to work using blocks. There are questions and answers to this, but all of them I found are solved by the use of CABasicAnimation and not by UIView Block-Based…
Unheilig
  • 16,196
  • 193
  • 68
  • 98
11
votes
3 answers

Trying to delay CABasicAnimation position and opacity of layer by 3 seconds but

I am trying to delay the animation of layer's opacity and position by 3 seconds using setBeginTime. I have called the layer boxLayer. The animation is going well however during the first 3 seconds (the layer is not supposed to show yet) the layer is…
Armand
  • 435
  • 1
  • 11
  • 23
10
votes
5 answers

running CABasicAnimation sequentially

How can I have one CABasicAnimation to run after the other one has finishes? In other words sequentially. I've added the begin time of the second animation, however it seems that the second animation doesn't gets executed: CABasicAnimation *…
adit
  • 32,574
  • 72
  • 229
  • 373
9
votes
3 answers

How to get solution for stopping/resuming CABasicAnimation working?

I'm using CABasicAnimation for rotating UIImageView and I'm unable to resume paused animation. The animation starts in viewDidLoad method: UIImageView *img = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"MyImage.png"]]; self.myImage =…
Centurion
  • 14,106
  • 31
  • 105
  • 197
9
votes
1 answer

Can't show animated CALayer in video using AVVideoCompositionCoreAnimationTool

UPDATE 6: I've managed to fix my issue completely but I still would like a better explanation than what I'm guessing is the reason it didn't work if I'm incorrect I've been trying to animate a sprite sheet over a video but every time I export the…
9
votes
1 answer

Animate CAShapeLayer with circle UIBezierPath and CABasicAnimation

I'd like to animate a circle from angle 0 to 360 degrees in 15 sec. The animation is weird. I know this is probably a start/end angle issue, I already faced that kind of problem with circle animations, but I don't know how to solve this one. var…
Marie Dm
  • 2,637
  • 3
  • 24
  • 43
9
votes
2 answers

CABasicAnimation flicker when applying the completion

I am trying to apply a rotation animation by number of degrees to a UIImageView and persist the rotation transformation in the completion block. The problem that I am facing is that when the completion block is executed there is a visible flicker…
Laur Stefan
  • 1,519
  • 5
  • 23
  • 50
9
votes
1 answer

How to get perfect X , Y position of rotating UIView in iOS

I am using CABasicanimation for rotate an UIView. I am using this code: CABasicAnimation *rotationAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"]; NSNumber *currentAngle = [CircleView.layer.presentationLayer…
Hardik Vyas
  • 1,973
  • 1
  • 20
  • 43
1
2
3
40 41