0

I want the imageview to fade and then hide completely.

Here is my code

   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"];

This is working properly but when the value becomes 0.0 the imageview should not appear again

j0k
  • 22,600
  • 28
  • 79
  • 90
user2185354
  • 519
  • 7
  • 23

2 Answers2

2

Actually there is no callback method for this so set the 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];  

following method called after animation completed

-(void)targetMethod
{
     flowerImageView.hidden = YES;
}
Pratik B
  • 1,599
  • 1
  • 15
  • 32
1

Yes, Pratik is on right way but image will be there just it wont be shown to you.

You can try following solution too, it will completely hide image.

 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];  

Then hide image completely after animation completes.

-(void)targetMethod
{
     [flowerImageView setHidden:YES];
}
Jayeshkumar Sojitra
  • 2,501
  • 4
  • 31
  • 44