我有五个按钮(一美元硬币),单击oneButton函数,即,硬币将移至框并显示resultText.text为1,第二个硬币将…。最多五枚硬币。

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

我怀疑这两个功能是否都正常运行


如果条件发生,eggamt为3。
如果条件发生,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];

}

最佳答案

您应该像下面这样测试:

-(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)
{
//...
}

关于ios - 如何设置文本字段的最大值,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/19311923/

10-10 19:13