0

誰かが私を正しい方向に導いてくれることを願っています。

ボタンが押された後、画面上の画像を一度に 1 つずつ更新できるようにする必要があります。それらはサイクルの終わりにのみ更新されるように見えますが、これは私がそれを機能させるために必要なものではありません。

私が何をしているのかを示すために、小さな例を作成しました。基本的に、画面に3つの画像があります。ボタンが押されたら、最初の画像を更新し、サウンドを再生し、1 秒待ってから次の画像を更新します。

ただし、1 つの音だけが聞こえ、最後にすべての画像が更新されます。

簡単なことのようです。どうすればいいですか?

#import "testappViewController.h"

@implementation testappViewController


@synthesize p1,p2,p3;   //UIImageViews
@synthesize button1;
@synthesize volleyFileID;

- (IBAction)buttonpressed:(id)sender
{
    NSString *TLS = @"RQP.png";

    NSString *volleyPath = [[NSBundle mainBundle] pathForResource:@"click" ofType:@"caf"];
    CFURLRef volleyURL = (CFURLRef ) [NSURL fileURLWithPath:volleyPath];
    AudioServicesCreateSystemSoundID (volleyURL, &volleyFileID);

    TLS = @"RQP.png"; 
    UIImage *sampleimage=   [[UIImage imageNamed:TLS] retain];
    p1.image = sampleimage; 
    AudioServicesPlaySystemSound(volleyFileID);

    [NSThread sleepForTimeInterval:0.5];

    p2.image = sampleimage; 
    AudioServicesPlaySystemSound(volleyFileID);

    [NSThread sleepForTimeInterval:0.5];

    p2.image = sampleimage; 
    AudioServicesPlaySystemSound(volleyFileID);

}
4

1 に答える 1

1

-[NSThread sleepForTimeInterval:] ここでは使用しないでください。-[NSObject performSelector:withObject:afterDelay:] を使用してみてください。後者の 2 つの画像は別のメソッドに変更されます。その後、イベント ループが通常どおり実行され、サウンドが再生され、実行中もアプリ全体の応答性が維持されます。

于 2009-06-17T23:14:27.137 に答える