0

我有五个(一美元硬币)作为一个按钮,单击一个按钮功能发生,即硬币将移动到盒子并显示 resultText.text 为 1,第二个硬币将......。最多五个硬币。

如果 resultText.text 等于或大于 eggamt 即 (eggamt = 3) 我将在 eggDanceAnimation 函数下面播放动画。

在这里,我怀疑这两个功能都可以正常工作

  1. 如果条件发生, eggamt 为 3。
  2. 如果条件发生,则 eggamt >3 否则。

问题是,我将四个硬币移动到盒子 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 回答