我希望imageview消失然后完全隐藏。
这是我的代码
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不应再次出现
答案 0 :(得分:2)
实际上没有回调方法,所以设置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;
}
答案 1 :(得分:1)
是的,Pratik是在正确的方式,但图像将在那里,只是它不会向你显示。
您也可以尝试以下解决方案,它会完全隐藏图像。
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 setHidden:YES];
}