2011-12-29 3 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

작업 순서가 다를 경우. 알파가 중요합니다. 이것은 아마도 그것이 만들어 질 수있는 가장 작은 것입니다.

-(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]; 
    } 
} 
관련 문제