0

基本的に、0.5 秒で 8 つの PNG をループする UIImageView があります。アニメーションを開始すると同時に、afterDelay を 0.5 秒にして performSelector を実行します。したがって、UIImageView のアニメーション化が終了した後、animationTickDone が呼び出され、最後の画像が非表示に設定されます。

とにかくコードは次のとおりです。

.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() が最初に呼び出されると、animateTickLast がアニメーションの後に表示されます。しかし、後で Found が再度呼び出されると、animatedTickDone が再び表示されることはありません。それは単なる空のスペースです。

何時間もウェブを検索して遊んだ後、なぜそれが表示されないのか、何が問題なのか理解できません。ある時点で、animatedTickLast が非表示を no に設定する前に sleep() が呼び出されると思っていましたが、sleep() を削除しても機能しませんでした。

今私を夢中にさせているので、どんな助けも大歓迎です。

ありがとう!

4

1 に答える 1

1

私があなたを正しく理解していれば、UIImageView のアニメーションの後に画像が必要です。アニメーションの前に画像をセットするだけでOK!

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