2 momo1199 Momo1199 于 2013.05.20 14:40 提问

UImagview实现渐变隐藏

实现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就完全隐藏起来。

2个回答

Mr_me
Mr_me   2013.05.20 15:43
已采纳

没有回掉方法,用一个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;
}
gaoXxxing
gaoXxxing   2013.05.20 15:26
 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];
}
Csdn user default icon
上传中...
上传图片
插入图片