【问题标题】:UImagview Fading and then hidingUImagview 淡出然后隐藏
【发布时间】:2013-05-13 08:39:29
【问题描述】:

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

【问题讨论】:

  • 淡出之后。您只需将其从超级视图(即 UIImageView)中删除。 [imageView removeFromSuperview].
  • 但是我怎么知道值变成了0

标签: iphone uiimageview cabasicanimation


【解决方案1】:

其实这个没有回调方法所以设置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;
}

【讨论】:

    【解决方案2】:

    是的,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];
    }
    

    【讨论】:

      猜你喜欢
      • 2015-09-16
      • 1970-01-01
      • 2015-07-15
      • 2011-11-16
      • 1970-01-01
      • 2011-07-04
      • 1970-01-01
      • 2022-06-13
      • 1970-01-01
      相关资源
      最近更新 更多