我有很多 UItextField,以及他们喜欢的动画:
-(void)textFieldDidBeginEditing: (UITextField *)textField{
NSLog(@"sowing keyboard");
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.27];
scroll1.frame = CGRectMake(0, -604, 768, 1004);
[UIView commitAnimations];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.47];
scroll2.frame = CGRectMake(0, 414, 768, 1004);
[UIView commitAnimations];
[UIView animateWithDuration:1.0
animations:^{
self.mapView.alpha=0.0;
}
completion:^(BOOL finished){
self.mapView.hidden=YES;
}];
}
-(void)textFieldDidEndEditing: (UITextField *)textField{
NSLog(@"hiding keyboard");
if (scroll2.frame.origin.y != 414) {
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.27];
scroll1.frame = CGRectMake(0, -340, 768, 1004);
[UIView commitAnimations];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.47];
scroll2.frame = CGRectMake(0, 678, 768, 1004);
[UIView commitAnimations];
[self.mapView setHidden:NO];
//fade in
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1.0];
[UIView setAnimationDelegate:self];
[self.mapView setAlpha:1.0];
[UIView commitAnimations];
}
}
问题是,如果我正在编辑一个字段,并且从我触摸并开始编辑另一个字段,则会调用代码 didEnd 和 DidBegin。我怎么能阻止它?我希望这些动画仅在我开始编辑文本字段并且没有正在编辑文本字段时出现,并且当我需要隐藏键盘时出现 DidEnd(当用户在 iPad 上按下 DownKey 时)
有任何想法吗??
我试过这个:
if (scroll2.frame.origin.y != 414) {
...它可以工作,但是当我按下重新运行键时,没有动画出现。