2011-12-29 4 views
0

私は自分のアプリケーションですべての機能を最小限にしようとしてきましたが、この機能をより良くする方法を見つけることができません。 :)このスニペットをもっときれいにする/よくする/少ない行にするにはどうすればよいですか?

-(void)showRivBoxWithAnimtation:(BOOL)yesno { 
    if(yesno) { 
     [UIView beginAnimations:nil context:NULL]; 
     [UIView setAnimationDuration:0.2]; 
     if ([self alpha] > 0) { 
      [self setAlpha:0.0]; 
      [appDelegate.JSONparser setDelegate:self.delegate]; //Give back the JSONparser to the parent! 
     } else { 
      [self setAlpha:1.0]; 
     } 
     [UIView setAnimationDelegate:self]; 
     [UIView setAnimationDidStopSelector:@selector(clearRivBoxContent:finished:context:)]; 
     [UIView commitAnimations]; 
    } else { 
     if ([self alpha] > 0) { 
      [self setAlpha:0.0]; 
      [appDelegate.JSONparser setDelegate:self.delegate]; //Give back the JSONparser to the parent! 
     } else { 
      [self setAlpha:1.0]; 
     } 
    } 
} 
+1

はhttp://codereview.stackexchange.comに属していますか? –

答えて

2

これは私がどうなるのかです:

-(void)showRivBoxWithAnimtation:(BOOL)yesno { 
    [UIView animateWithDuration:yesno ? 0.2 : 0.0 
        animations:^{ 
     if ([self alpha] > 0) { 
      [self setAlpha:0.0]; 
      [appDelegate.JSONparser setDelegate:self.delegate]; //Give back the JSONparser to the parent! 
     } else { 
      [self setAlpha:1.0]; 
     } 
     } 
        completion:^(BOOL finished){ 
     if (finished) { 
      // Do the stuff from clearRivBoxContent:finished:context: 
     } 
    }]; 
} 
+0

そこに素敵なもの:) – Hjalmar

+0

それは私の答えよりも良い方法です。 –

0

操作の順序がwrtでない限り、アルファは重要です。これはおそらくそれができる最小です。

-(void)showRivBoxWithAnimtation:(BOOL)yesno { 
    if ([self alpha] > 0) { 
    [self setAlpha:0.0]; 
    [appDelegate.JSONparser setDelegate:self.delegate]; //Give back the JSONparser to the parent! 
    } else { 
    [self setAlpha:1.0]; 
    } 

    if(yesno) { 
    [UIView beginAnimations:nil context:NULL]; 
    [UIView setAnimationDuration:0.2]; 
    [UIView setAnimationDelegate:self]; 
    [UIView setAnimationDidStopSelector:@selector(clearRivBoxContent:finished:context:)]; 
    [UIView commitAnimations]; 
    } 
} 
関連する問題