實現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;
}