0

ボタンがクリックされると 5 つ (1 ドル コイン) があり、oneButton 関数が実行されます。つまり、コインがボックスに移動し、結果テキストが表示されます。コインは5枚まで。

resultText.text が eggamt 以上の場合 (eggamt = 3)、eggDanceAnimation 関数の下でアニメーションを再生します。

ここで私の疑問は、両方の機能が完全に機能していることです

  1. 条件が発生した場合、egamt は 3 です。
  2. 状態が発生した場合、egamt は >3 です。

問題は、4 つのコインをボックスに移動した結果、resultText.text はディスプレイ 4 であり、アニメーションを再生する実際の要件は、resultText.text がディスプレイ 3 であり、アニメーションを再生することです。

-(void)eggDanceAnimation {
 if (counter == 0 && [resultText.text isEqualToString:eggamt]){

     NSLog(@"%i", counter);
     [self hideObjectAnimationDidStart];

     NSArray *dashBoy;
     dashBoy = [[NSArray alloc] initWithObjects:
           [UIImage imageNamed:@"a10001.png"], [UIImage imageNamed:@"a10002.png"], [UIImage imageNamed:@"a10003.png"], nil];
     stgImage1.animationImages = dashBoy;
     stgImage1.animationDuration = 1;
     [stgImage1 startAnimating];
 }

else if(counter==0 && [resultText.text compare:eggamt options:NSNumericSearch range:range]==NSOrderedDescending) {
   stgImage1.image = [UIImage imageNamed:@"eggDanceHide.png"];
   stgText1.text= @"Oops! That is too much money, lets try again.";

   oneBtn1.hidden = YES;oneBtn2.hidden = YES;oneBtn3.hidden = YES;oneBtn4.hidden = YES;oneBtn5.hidden = YES;
   tenBtn1.hidden = YES;tenBtn2.hidden = YES;tenBtn3.hidden = YES;tenBtn4.hidden = YES;tenBtn5.hidden = YES;
   fiveBtn1.hidden = YES;fiveBtn2.hidden = YES;fiveBtn3.hidden = YES;
   fiveBtn4.hidden = YES;fiveBtn5.hidden = YES;
   twentyFiveBtn1.hidden = YES;twentyFiveBtn2.hidden = YES;twentyFiveBtn3.hidden = YES;
   twentyFiveBtn4.hidden = YES;twentyFiveBtn5.hidden = YES;
   amtText.hidden = YES;

}
}

- (void)oneButton:(UIButton*)oneBtn {

CGRect frame = oneBtn.frame;
CGRect frame1 = reffButton.frame;
frame.origin.x = frame1.origin.x; 
frame.origin.y = frame1.origin.y; 

[UIView beginAnimations:nil context:nil];

[UIView setAnimationDuration: 3.0];
[UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
[UIView animateWithDuration:3.0 animations:^{
    [oneBtn setTransform:CGAffineTransformMakeScale(.4, .4)];


} completion:^(BOOL finished) {
    oneBtn.hidden = YES;
        price = [resultText.text intValue];
        NSString *result=[NSString stringWithFormat:@"%i", price+1];
        [resultText setText:result];

        [[NSUserDefaults standardUserDefaults] setValue:result forKey:@"key"];
        [[NSUserDefaults standardUserDefaults] synchronize];


        [self eggDanceAnimation]; 

}];
oneBtn.frame = frame;
[UIView commitAnimations];

}
4

1 に答える 1

1

次のように何かをテストする必要があります。

-(void)eggDanceAnimation {
int resultInt = [result.text intValue];
int eggInt = [eggamt intValue];
NSLog(@"Result is %d ; Eggamt is %d",resultInt,eggInt);

次に、intを使用して必要なものを比較します(NSStringを使用するよりも優れています)

if (eggInt == resultInt)
{
//...
}
else if (eggInt < resultInt)
{
//...
}
于 2013-10-11T10:18:04.573 に答える