ボタンを押すと別のスレッドが開始され、読み込み中のアニメーションが表示されます。これを行う理由は、ボタンを押すとすぐにロード中のgifが表示され、他の手順が続行され、アラートが完了すると表示されるためです。私が持っている問題は、アラートが閉じられた後にアニメーションが隠れていることです。別のスレッドでタスクが完了した後に、1つのスレッドで実行中のアニメーションを非表示にしています
- (IBAction)buttonPressed:(id)sender {
[NSThread detachNewThreadSelector:@selector(loadAnimation) toTarget:self withObject:nil];
... do other things;
UIAlertView *alert = [[UIAlertView alloc]initWithTitle: @"Complete" message:@"other things done" delegate: self cancelButtonTitle:@"OK" otherButtonTitles: nil];
[alert setTag:1];
[alert show];
}
-(void) alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
if (alertView.tag == 1) {
loadingGif.hidden=YES;
}
}
ロードGIF:
- (void) loadAnimation {
loadingGif.hidden=NO;
NSArray *imageArray = [[NSArray alloc] initWithObjects:[UIImage imageNamed:@"0.gif"], [UIImage imageNamed:@"1.gif"], [UIImage imageNamed:@"2.gif"], [UIImage imageNamed:@"3.gif"], nil];
loadingGif = [[UIImageView alloc] initWithFrame:CGRectMake(487, 520, 50, 50)];
[self.view addSubview:loadingGif];
loadingGif.animationImages = imageArray;
loadingGif.animationDuration = 1.5;
[loadingGif startAnimating];
}
アニメーション負荷罰金はなく、アラートからOKがクリックされたら、それは停止しません。メインスレッドが別のスレッドで開始された後にアニメーションをメインスレッドから隠すことは可能ですか?
答えに感謝します。それは同様の(警告なしで)読み込み用GIFを隠すので、それを説明します。私はそれにgoを与えるでしょう。ありがとう – RGriffiths
@RGriffiths不要なブロックを削除するために私のコードを変更しました。申し訳ありません。 – negaipro