How to animate the background color of a UILabel?

I can’t find it documented anywhere, but it appears the backgroundColor property of UILabel is not animatable, as your code works fine with a vanilla UIView. This hack appears to work, however, as long as you don’t set the background color of the label view itself: #import <QuartzCore/QuartzCore.h> … theLabel.layer.backgroundColor = [UIColor whiteColor].CGColor; [UIView animateWithDuration:2.0 … Read more

Is there a way to pause a CABasicAnimation?

Recently appeared Apple’s technical note QA1673 describes how to pause/resume layer’s animation. Pause and resume animations listing is below: -(void)pauseLayer:(CALayer*)layer { CFTimeInterval pausedTime = [layer convertTime:CACurrentMediaTime() fromLayer:nil]; layer.speed = 0.0; layer.timeOffset = pausedTime; } -(void)resumeLayer:(CALayer*)layer { CFTimeInterval pausedTime = [layer timeOffset]; layer.speed = 1.0; layer.timeOffset = 0.0; layer.beginTime = 0.0; CFTimeInterval timeSincePause = [layer convertTime:CACurrentMediaTime() … Read more

iPhone UIView Animation Best Practice

From the UIView reference‘s section about the beginAnimations:context: method: Use of this method is discouraged in iPhone OS 4.0 and later. You should use the block-based animation methods instead. Eg of Block-based Animation based on Tom’s Comment [UIView transitionWithView:mysuperview duration:0.75 options:UIViewAnimationTransitionFlipFromRight animations:^{ [myview removeFromSuperview]; } completion:nil];

UIButton can’t be touched while animated with UIView animateWithDuration

Swift 5 In my case, when I set button.alpha = 0, the button interaction stops working, no matter if I setup UIViewAnimationOptionAllowUserInteraction as an option. Reason Whenever you define the animation or not, the view’s property is applying to view’s layer immediately. Because of this, when you set the view.alpha=0, you hide the view completely. … Read more

UIView Infinite 360 degree rotation animation?

Found a method (I modified it a bit) that worked perfectly for me: iphone UIImageView rotation #import <QuartzCore/QuartzCore.h> – (void) runSpinAnimationOnView:(UIView*)view duration:(CGFloat)duration rotations:(CGFloat)rotations repeat:(float)repeat { CABasicAnimation* rotationAnimation; rotationAnimation = [CABasicAnimation animationWithKeyPath:@”transform.rotation.z”]; rotationAnimation.toValue = [NSNumber numberWithFloat: M_PI * 2.0 /* full rotation*/ * rotations * duration ]; rotationAnimation.duration = duration; rotationAnimation.cumulative = YES; rotationAnimation.repeatCount = repeat … Read more