How to crossfade between 2 images on iPhone using Core Animation

You were almost there. CABasicAnimation *crossFade = [CABasicAnimation animationWithKeyPath:@”contents”]; crossFade.duration = 5.0; crossFade.fromValue = image1.CGImage; crossFade.toValue = image2.CGImage; [self.imageView.layer addAnimation:crossFade forKey:@”animateContents”]; Note that the animation is independent of the actual values/contents of the UIImageView. Therefore you’ll need to self.imageView.image = image2; … to set the final result for your image.

How is the relation between UIView’s clipsToBounds and CALayer’s masksToBounds?

They are different names because UIView and CALayer are different and have different terminology associated with them, but they are functionally equivalent. If you disassemble clipsToBounds you will see it just calls masksToBounds (disassembly from the simulator framework, so x86): -(BOOL)[UIView(Rendering) clipsToBounds] +0 3091938a 55 pushl %ebp +1 3091938b 89e5 movl %esp,%ebp +3 3091938d e800000000 … Read more

UIView vertical flip animation

Just write your own method for the flip using Core Animation Transforms. – (void)verticalFlip{ [UIView animateWithDuration:someDuration delay:someDelay animations:^{ yourView.layer.transform = CATransform3DMakeRotation(M_PI,1.0,0.0,0.0); } completion:^{ // code to be executed when flip is completed }]; } Make sure you have the Core Animation libraries/frameworks added and included and also have included math.h if you want to use … Read more

How to identify CAAnimation within the animationDidStop delegate?

Batgar’s technique is too complicated. Why not take advantage of the forKey parameter in addAnimation? It was intended for this very purpose. Just take out the call to setValue and move the key string to the addAnimation call. For example: [[hearingAidHalo layer] addAnimation:animation forKey:@”Throb”]; Then, in your animationDidStop callback, you can do something like: if … Read more

Create a custom animatable property

If you extend CALayer and implement your custom – (void) drawInContext:(CGContextRef) context You can make an animatable property by overriding needsDisplayForKey (in your custom CALayer class) like this: + (BOOL) needsDisplayForKey:(NSString *) key { if ([key isEqualToString:@”percentage”]) { return YES; } return [super needsDisplayForKey:key]; } Of course, you also need to have a @property called … Read more

Animating a custom property of CALayer subclass

Yes, it’s possible (only in the latest Core Animation releases though, I believe, i.e. iPhone 3.0+ and OS X 10.6+). Make your property dynamic so that CA implements the accessors for you: @dynamic myInt; Tell the layer that changes of the property require redrawing: + (BOOL)needsDisplayForKey:(NSString*)key { if ([key isEqualToString:@”myInt”]) { return YES; } else … Read more

Animation End Callback for CALayer?

You could use a CATransaction, it has a completion block handler. [CATransaction begin]; CABasicAnimation *pathAnimation = [CABasicAnimation animationWithKeyPath:@”strokeEnd”]; [pathAnimation setDuration:1]; [pathAnimation setFromValue:[NSNumber numberWithFloat:0.0f]]; [pathAnimation setToValue:[NSNumber numberWithFloat:1.0f]]; [CATransaction setCompletionBlock:^{_lastPoint = _currentPoint; _currentPoint = CGPointMake(_lastPoint.x + _wormStepHorizontalValue, _wormStepVerticalValue);}]; [_pathLayer addAnimation:pathAnimation forKey:@”strokeEnd”]; [CATransaction commit];