2014-03-24 1 views
0

나는 단어 게임을 고쳐서 사용자가 팁을 얻을 수있는 버튼을 만들었지 만 팁은 10 동전을 소비합니다.사용자가 동전이 충분하지 않은 경우 작업을 차단하는 방법은 무엇입니까?

사용자가 동전을 남기지 않고 동시에 동전을 구입하지 않도록 조치 할 수 있습니까? 이 같은

-(IBAction)btnHint:(id)sender { 
    [UIView beginAnimations:nil context:NULL]; 
    [UIView setAnimationDuration:0.5]; 

    CGPoint center = [hints center]; 
    center.x = 160; 
    center.y = 230; 
    [hints setCenter:center]; 

    [UIView commitAnimations]; 
    hintView.text = @"founded in 1996, and is a sub of telecome"; 

    coins = coins -10; 
} 
+0

조건을 검사하는'if' 문을 추가하십시오. – rmaddy

+0

당신의 메시지와 함께 UIAlert를 보여주세요. –

+0

@rmaddy 그렇습니다. 그렇지만 stamens 애니메이션이 계속 올라가고 팁이 노출 될 경우, 애니메이션 또한 올라가지 않도록 막아야합니다. 어떻게 이루어 집니까? if (동전 == 0) { [hintView setHidden : YES]; } 단어는 힌트를 숨기지 만 애니메이션을 중단시키지 않습니다. – JohnGray

답변

1

뭔가 :

- (IBAction)btnHint:(id)sender { 
    if (/* some condition that determines if there are enough coins */) { 
     [UIView beginAnimations:nil context:NULL]; 
     [UIView setAnimationDuration:0.5]; 

     CGPoint center = [hints center]; 
     center.x = 160; 
     center.y = 230; 
     [hints setCenter:center]; 

     [UIView commitAnimations]; 
     hintView.text = @"founded in 1996, and is a sub of telecome"; 

     coins = coins -10; 
    } else { 
     // show alert 
    } 
} 

BTW - 당신은 정말 현대 블록 기반 UIView 애니메이션 대신 사용하는 옛날 방식으로 마이그레이션해야합니다.

+0

그래, 나는이 if 문에 더 큰 문제가있다. 동전이 제대로 합쳐지지 않는다. 동전과 점수를 합산하는 적절한 방법은 무엇일까? – JohnGray

+0

그건 별개의 질문입니다. 이 사람이 대답하면이 대답을 수락하고 필요에 따라 다른 질문을 게시하십시오. – rmaddy

+0

예! 당장, 고마워! – JohnGray

관련 문제