0

基本上,我有一个 UIImageView 将在 0.5 秒内循环通过 8 个 PNG。在开始动画的同时,我做了一个 afterDelay 为 0.5 秒的 performSelector。所以在我的 UIImageView 完成动画之后,它会调用 animationTickDone ,它将最后一个图像隐藏为 no。

无论如何,这是代码:

.h
@interface ViewController : UIViewController{
    IBOutlet UIView *scannedView;
    IBOutlet UIImageView *animatedTickLast;
}
@property (nonatomic, retain) IBOutlet UIView *scannedView;
@property (nonatomic, retain) IBOutlet UIImageView *animatedTickLast;

.m
-(void)Found{
        [self.view addSubview:scannedView];
        [animatedTickLast setHidden:YES];
        //place animated tick images into an array
        NSMutableArray *animatedTickImages;
        animatedTickImages = [[NSMutableArray alloc] init];
        NSUInteger nimages = 0;
        for (nimages=0; nimages<8; nimages++){
            NSString *tickImageName = [NSString stringWithFormat:@"tick_%d.png", (nimages + 1)];
            [animatedTickImages addObject:[UIImage imageNamed:tickImageName]];
        }
        //set up animated tick
        UIImageView *animatedTick = [[UIImageView alloc] initWithFrame:CGRectMake(98, 213, 125, 90)];
        [animatedTick setAnimationImages:animatedTickImages];
        [animatedTick setAnimationDuration:0.5];
        [animatedTick setAnimationRepeatCount:1];
        [animatedTick startAnimating];
        NSLog(@"animation started");
        [self performSelector:@selector(animationTickDone) withObject:nil afterDelay:0.5];
        [scannedView addSubview:animatedTick];
        NSLog(@"animation added into view");
        [animatedTickImages release];
}
- (void)animationTickDone{
    NSLog(@"delay function begins");
    [animatedTickLast setHidden:NO];
    sleep(1); //sleep so that scannedView stays on screen for at least 1.5 seconds (0.5 after animation + 1 from sleep);
}

现在,问题。动画本身很好,效果很好。但是当第一次调用 Found() 时,animatedTickLast 将在动画结束后变得可见。但是,当 Found 再次被调用后,animatedTickDone 再也不会出现,它只是一个空白空间。

经过数小时的网络搜索和使用它,我无法理解为什么它没有出现的问题。我认为在我的 animatedTickLast 有机会将 hidden 设置为 no 之前调用了 sleep() ,但是在删除 sleep() 之后它仍然不起作用。

现在让我发疯,非常感谢任何帮助。

谢谢!

4

1 回答 1

1

如果我理解正确,您需要 UIImageView 中的动画之后的图像。只需在动画之前设置图像就可以了!

[animatedTick setAnimationImages:animatedTickImages];
[animatedTick setAnimationDuration:0.5];
[animatedTick setAnimationRepeatCount:1];
[animatedTick setImage:theImageYouLikeToHave];
[animatedTick startAnimating];
于 2012-07-02T14:40:40.303 回答