实现UImagview渐变然后隐藏。
代码:
CABasicAnimation *theAnimation;
theAnimation=[CABasicAnimation animationWithKeyPath:@"opacity"];
theAnimation.duration=1.0;
theAnimation.fromValue=[NSNumber numberWithFloat:1.0];
theAnimation.toValue=[NSNumber numberWithFloat:0.0];
[flowerImageView.layer addAnimation:theAnimation forKey:@"animateOpacity"];
没实现等到值成为0.0时,imageView就完全隐藏起来。
没有回掉方法,用一个NSTimer
CABasicAnimation *theAnimation;
theAnimation=[CABasicAnimation animationWithKeyPath:@"opacity"];
theAnimation.duration=1.0;
theAnimation.fromValue=[NSNumber numberWithFloat:1.0];
theAnimation.toValue=[NSNumber numberWithFloat:0.0];
[flowerImageView.layer addAnimation:theAnimation forKey:@"animateOpacity"];
[NSTimer scheduledTimerWithTimeInterval:theAnimation.duration
target:self
selector:@selector(targetMethod)
userInfo:nil
repeats:NO];
在动画结束后调用:
-(void)targetMethod
{
flowerImageView.hidden = YES;
}
CABasicAnimation *theAnimation;
theAnimation=[CABasicAnimation animationWithKeyPath:@"opacity"];
theAnimation.duration=1.0;
theAnimation.fromValue=[NSNumber numberWithFloat:1.0];
theAnimation.toValue=[NSNumber numberWithFloat:0.0];
[flowerImageView.layer addAnimation:theAnimation forKey:@"animateOpacity"];
[NSTimer scheduledTimerWithTimeInterval:theAnimation.duration
target:self
selector:@selector(targetMethod)
userInfo:nil
repeats:NO];
在动画结束后,imageview就会完全隐藏。
-(void)targetMethod
{
[flowerImageView setHidden:YES];
}