每次按下检查按钮,键盘都会理解我按下了它!
如果用户甚至没有在文本字段中输入任何内容,则向用户提供错误答案是没有意义的
那么,如果用户按下第一件事,我怎么能阻止我的检查按钮才能识别它??
- (IBAction)btncheck:(id)sender {
NSString *answer = [_textbox.text stringByReplacingOccurrencesOfString:@" " withString:@""];
if ([answer isEqualToString:@"q"]) {
// String is correct, resign keyboard
_keyboard.hidden = YES;
_textXclear.hidden = YES;
//Perfect button
[_closeone setHidden:NO];
[_wrongone setHidden:YES];
}
else {
// Was not correct. Notify user, or just don't do anything
[_wrongone setHidden:NO];
// animation that shakes the image (qimage)
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.03];
[UIView setAnimationDelay:0.15];
[UIView setAnimationRepeatCount:0];
[UIView setAnimationRepeatAutoreverses:YES]
qimage.transform = CGAffineTransformMake(1.08, 0, 0, 1, 0, 1.);
qimage.transform = CGAffineTransformMakeTranslation(0,0);
}
最后,其他名副其实的是需要修复的动画,那么当用户得到错误答案时,将UIImage设置为动画/振动/地震效果或从左向右摇动的正确方法是什么?
答案 0 :(得分:0)
为什么不先检查空字符串?
if([answer isEqualToString:@""]) {
//do nothing
} else {
//do your stuff
if ([answer isEqualToString:@"q"]) {
// String is correct, resign keyboard
_keyboard.hidden = YES;
_textXclear.hidden = YES;
//Perfect button
[_closeone setHidden:NO];
[_wrongone setHidden:YES];
}
else {
// Was not correct. Notify user, or just don't do anything
[_wrongone setHidden:NO];
// animation that shakes the image (qimage)
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.03];
[UIView setAnimationDelay:0.15];
[UIView setAnimationRepeatCount:0];
[UIView setAnimationRepeatAutoreverses:YES]
qimage.transform = CGAffineTransformMake(1.08, 0, 0, 1, 0, 1.);
qimage.transform = CGAffineTransformMakeTranslation(0,0);
}
}