我有图像视图,如果单击按钮说话tom cat将播放animationRepeatCount:2,此后,我想隐藏图像视图。如何隐藏图像视图?
- (IBAction)catBlinkButton:(UIButton *)sender {
self.imageView.hidden = NO;
self.imageView.animationDuration = 2;
self.imageView.animationRepeatCount = 2;
self.imageView.animationImages = [[NSArray alloc]initWithObjects:
[UIImage imageNamed:@"cat_blink0000.png"],
[UIImage imageNamed:@"cat_blink0001.png"],
[UIImage imageNamed:@"cat_blink0002.png"],
nil];
[self.imageView startAnimating];
}
这是我的代码......
答案 0 :(得分:10)
您可以简单地使用CATransaction
,如:
self.imageView.hidden = NO;
[CATransaction begin];
[CATransaction setCompletionBlock:^{
self.imageView.hidden = YES;
}];
self.imageView.animationDuration = 2;
self.imageView.animationRepeatCount = 2;
self.imageView.animationImages = [[NSArray alloc]initWithObjects:
[UIImage imageNamed:@"cat_blink0000.png"],
[UIImage imageNamed:@"cat_blink0001.png"],
[UIImage imageNamed:@"cat_blink0002.png"],
nil];
[self.imageView startAnimating];
[CATransaction commit];
CATransaction
将动态等待动画完成...
答案 1 :(得分:2)
您可以在主线程上执行平板后的代码。
- (IBAction)catBlinkButton:(UIButton *)sender {
self.imageView.hidden = NO;
self.imageView.animationDuration = 2;
self.imageView.animationRepeatCount = 2;
self.imageView.animationImages = [[NSArray alloc]initWithObjects:
[UIImage imageNamed:@"cat_blink0000.png"],
[UIImage imageNamed:@"cat_blink0001.png"],
[UIImage imageNamed:@"cat_blink0002.png"],
nil];
[self.imageView startAnimating];
// after 2 seconds.
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 2 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
// hide imageview
self.imageView.hidden = YES;
});
}
答案 2 :(得分:1)
你可以使用UIView的隐藏属性来做到这一点。 imageView.hidden = true;
答案 3 :(得分:1)
- (IBAction)catBlinkButton:(UIButton *)sender {
self.imageView.hidden = NO;
self.imageView.animationDuration = 2;
self.imageView.animationRepeatCount = 2;
self.imageView.animationImages = [[NSArray alloc]initWithObjects:
[UIImage imageNamed:@"cat_blink0000.png"],
[UIImage imageNamed:@"cat_blink0001.png"],
[UIImage imageNamed:@"cat_blink0002.png"],
nil];
[self.imageView startAnimating];
}