2011-05-21 11 views
0

こんにちは 特定のイベントが発生すると、私はいくつかのメソッド(ゲーム内のロック解除されたトロフィー)を呼び出し、それらは表示され、サブビューが消えます。 クラッシュ(正しく)は、これらのイベントが同時に発生して重複した場合に発生します。 どうすれば "あなたの番を待ってください:)"を確認できますか?これらのイベントが同時に発生し、重なる場合 おかげメソッド "あなたのターンを待つ"!

-(void)trofeiLaunch:(int)x { 


    CGRect loseFrame = CGRectMake(0, 0, 480, 320); 
    TrofeoView = [[UIView alloc] initWithFrame:loseFrame]; 
    TrofeoView.alpha = 0.0; 
    [UIView beginAnimations:nil context:self]; 
    [UIView setAnimationCurve:UIViewAnimationCurveEaseOut]; 
    [UIView setAnimationDuration:0.5]; 
    [UIImageView setAnimationDelegate:self]; 
    TrofeoView.alpha = 1.0; 
    [UIView setAnimationDidStopSelector:@selector(bridgeTrofei)]; 
    [UIView commitAnimations]; 
    [self.view addSubview:TrofeoView]; 
    [TrofeoView release]; 

      .... 

} 

-(void)bridgeTrofei { 

TrofeoView.alpha = 1.0; 
[UIView beginAnimations:nil context:self]; 
[UIView setAnimationCurve:UIViewAnimationCurveEaseOut]; 
[UIView setAnimationDuration:0.5]; 
[UIView setAnimationDelegate:self]; 
TrofeoView.alpha = 0.0; 
[UIView commitAnimations]; 
[self performSelector:@selector(deleteTrofei) withObject:self afterDelay:1.0]; 

} 


-(void)deleteTrofei { 


[TrofeoView removeFromSuperview]; 

NSLog(@"delete"); 

} 

クラッシュ(正しく)が発生します。 どうすれば "あなたの番を待ってください:)"を確認できますか? ありがとう

+0

あなたはどんな種類のクラッシュを見ていますか?メイン選択ラインの – Anomie

+0

:int retVal = UIApplicationMain(argc、argv、nil、nil);コンパイラで:sharedlibrary apply-load-rules all 現在の言語:auto;現在objective-c – Vins

答えて

1

最初のアニメーションが完了する前に2番目のアニメーションが開始された場合、TrofeoViewが再割り当てされ、以前の参照が失われます。また、 'trofeiLaunch: `メソッドでTrofeoViewをリリースすると、メモリ管理ルールが暴走することもあります。この変数は後で所有権を取得した後に再度使用します。あなたはあなたがそれで終わっていない場合にのみ、オブジェクトをリリースするべきです。

私は、この道を行く最も重要なことは、3つのメソッドが正しいオブジェクトを参照していることを確認することだと思います。最初の1つはデフォルトでokですので、次の2つを処理する必要があります。私はそれを行うためにあなたのコードを修正しました。

- (IBAction)start { 

    animatingView = [[UIView alloc] initWithFrame:CGRectMake(100, 100, 200, 200)]; 
    animatingView.backgroundColor = [UIColor greenColor]; 
    animatingView.alpha = 0.0; 
    [UIView beginAnimations:@"Trophy Display" context:animatingView]; 
    [UIView setAnimationCurve:UIViewAnimationCurveEaseOut]; 
    [UIView setAnimationDuration:0.5]; 
    [UIImageView setAnimationDelegate:self]; 
    [UIView setAnimationDidStopSelector:@selector(animationDidStop:finished:context:)]; 
    animatingView.alpha = 1.0; 
    [UIView commitAnimations]; 
    [self.window addSubview:animatingView]; 
} 

- (void)animationDidStop:(NSString*)animationID finished:(NSNumber*)finished context:(void *)context { 

    if ([animationID isEqualToString:@"Trophy Display"]) { 
     UIView *aView = (UIView *)context; 

     [UIView beginAnimations:nil context:aView]; 
     [UIView setAnimationCurve:UIViewAnimationCurveEaseOut]; 
     [UIView setAnimationDuration:0.5]; 
     [UIView setAnimationDelegate:self]; 
     aView.alpha = 0.0; 
     [UIView commitAnimations]; 
     [self performSelector:@selector(finishAnimation:) withObject:aView afterDelay:1.0]; 
    } 
} 

- (void)finishAnimation:(UIView*)aView { 
    [aView removeFromSuperview]; 
    [aView release]; 
} 

Iは、第三の方法の第二の方法とwithObject:部にcontextを介してビューを渡します。私はコードが自明であることを望んでいます。あなたがこれを取得していない場合私に知らせてください。

次の点は正しいかどうかです。配列を使ってこれを管理できませんか?表示されているビューがない場合にのみプッシュします。

+0

素晴らしい!!!ありがとう!メモリに関する情報をお寄せいただきありがとうございます:) – Vins

関連する問題