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

Fade background-color from one color to another in a UIView

How can I fade from one background-color to another color in a UIView? In javascript (jQuery) it can be done by doing the following: $('body').animate({ backgroundColor: "#ff00ff"}); Would it be easier if I converted the colors to HSV? EDIT: Tried…
johankj
  • 1,765
  • 16
  • 34
5
votes
1 answer

CABasicAnimation drawing a path does not scale when superView's scale changes

I have an animation of drawing a rectangle to a specific percentage of it. For that i am drawing a CAShapeLayer: func drawTheLayer() -> CAShapeLayer { let lineWidth: CGFloat = borderWidth * bounds.size.width / standardSizeWidth let…
Mihriban Minaz
  • 3,043
  • 2
  • 32
  • 52
5
votes
2 answers

CABasicAnimation reverse(backwards)

I'm a bit struggling with this simple line animation. I figured out how to pause it, but what I need is to be able to reverse animation back to starting point from the moment I call function resetAnimation(). let pathAnimation =…
Linas Vildziunas
  • 171
  • 1
  • 6
  • 12
5
votes
2 answers

Do I need to remove CABasicAnimation when the animation is finished?

I am animating a layer like so to change the background color: CALayer *layer = [CALayer layer]; layer.frame = CGRectMake(0, self.view.bounds.size.height, self.view.bounds.size.width, self.view.bounds.size.height); …
KexAri
  • 3,867
  • 6
  • 40
  • 80
5
votes
3 answers

Animate Background Color Of UIButton from WhiteColor to RedColor

I'm trying to making a kind of color pulse effect animating background color of a UIButton to make it change continously from a color (WhiteColor) to another one (RedColor). I'm trying to use CABasicAnimation for changing Opacity but I can't make it…
pipizanzibar
  • 319
  • 3
  • 12
5
votes
3 answers

iOS Animate Rotation at an Angle

I'm trying to do a 360 spin of a view but at a 45 degree tilt. Like this I can't figure out for to do it. So far I've managed this CABasicAnimation* animation = [CABasicAnimation …
Mark Bridges
  • 8,228
  • 4
  • 50
  • 65
5
votes
3 answers

Why when I set a low duration value for my CABasicAnimation does it jump?

Sample Project: http://cl.ly/1W3V3b0D2001 I'm using CABasicAnimation to create a progress indicator that is like a pie chart. Similar to the iOS 7 app download animation: The animation is set up as follows: - (void)drawRect:(CGRect)rect { …
Doug Smith
  • 29,668
  • 57
  • 204
  • 388
5
votes
1 answer

How to make UI object responsive after CABasicAnimation

I'm having trouble trying to find a way to make my UI object (UISegmentedControl) touch responsive after a CABasicAnimation slide in and bounce. How can I pull this off? I know the UI object is in the presentation tree after the move. But I really…
Troy R
  • 426
  • 2
  • 16
5
votes
2 answers

Correct way to prevent disappearing layer in CABasicAnimation?

I'm animating a CALayer using CABasicAnimation and expecting the layer to remain in position when the animation completes. Nearly all solutions show the following, which works fine animation.removedOnCompletion = NO; animation.fillMode =…
Steve
  • 988
  • 1
  • 12
  • 25
5
votes
1 answer

Is "affineTransform" a valid CALayer keypath for setting up CABasicAnimation

This seems like a really basic question that has been surprisingly hard to find an answer to. CABasicAnimations set up with "affineTransform" as the keypath haven't worked for me, and in a bunch of places I've seen people eventually resorting to…
Dev Kanchen
  • 2,332
  • 3
  • 28
  • 40
5
votes
1 answer

IOS Coreplot scatterplot animation drawing

I need to animate in ios a scatterplot to make it as the line was drawing. There is a similar effect in this website http://www.highcharts.com .I tried unsuccessfully with basic animation but impossible to make this effect. Does anyone has any idea…
user1629713
  • 146
  • 4
5
votes
3 answers

changing image during translation

How can I change myLayer.contents with a set of images (i.e. switching between img1 and img2) during the translation? thanks! UIImage *myImage = [UIImage imageNamed:@"img1.png"]; CALayer *myLayer = [CALayer layer]; myLayer.contents =…
Beppino66
  • 1,709
  • 2
  • 13
  • 15
5
votes
1 answer

how to loop several CABasicAnimations contained in a CATransaction block?

Using Obj.-c for iPhone 5.1 in Xcode 4.3.2; I create an array of CALayers, all from the same image. I then wish to apply a CABasicAnimation to each CALayer in the array simultaneously by grouping via CATransactions. This all works one time. …
4
votes
1 answer

pausing and resuming core animation when app enters and exits background

I have a simple CABasicAnimation wired up as an infinite animation (I have a wheel that I keep rotating forever). Here is the method where I setup that explicit animation: -(void)perform360rotation:(UIImageView*) imageView { CABasicAnimation* anim =…
aloha
  • 1,561
  • 13
  • 26
4
votes
1 answer

iOS UIView properties don't animate with CABasicAnimation

I can imagine a far amount of sighs when people see this question popup again. However, I have read through a lot of information both here, in the documentation and via Google and still haven't found a solution. So here goes nothing. I'm trying to…
ChezFre
  • 6,502
  • 1
  • 19
  • 25