我有五个(一美元硬币)作为按钮点击oneButton功能发生,即硬币将移动到框并显示resultText.text为1,第二个硬币将...是最多五个硬币。
如果resultText.text等于或大于eggamt,即(eggamt = 3),我将播放eggDanceAnimation函数下面的动画。
我怀疑这两项功能是否完美无缺
问题是,我将四个硬币移动到框中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];
}
答案 0 :(得分: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)
{
//...
}