0

我希望图像视图消失然后完全隐藏。

这是我的代码

   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 时,图像视图不应再次出现

4

2 回答 2

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;
}
于 2013-05-18T07:02:27.597 回答
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];
}
于 2013-05-18T07:24:13.323 回答