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, изображение не должно появляться снова
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;
}
Да, Пратик на правильном пути, но изображение будет там, просто оно не будет показано вам.
Вы также можете попробовать следующее решение, оно полностью скроет изображение.
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];
}