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, изображение не должно появляться снова.


person user2185354    schedule 18.05.2013    source источник
comment
После того, как погаснет. Вы просто удаляете его из супервизора (это UIImageView). [imageView removeFromSuperview].   -  person jamil    schedule 18.05.2013
comment
но как я узнаю, что значение стало 0   -  person user2185354    schedule 18.05.2013
comment
Посмотрите здесь stackoverflow.com/a/11487269/1328096.   -  person jamil    schedule 18.05.2013


Ответы (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;
}
person pratik bhiyani    schedule 18.05.2013

Да, 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];
}
person Jayeshkumar Sojitra    schedule 18.05.2013