gpt4 book ai didi

ios - 在第二次 UITextField 编辑时显示和隐藏键盘

转载 作者:行者123 更新时间:2023-11-29 04:26:09 36 4
gpt4 key购买 nike

我有很多 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];

}
}

问题是,如果我正在编辑一个字段,并且从他们的 i touch 开始编辑另一个字段,则会调用代码 didEnd 和 DidBegin。我怎样才能阻止它?我希望这些动画仅在我开始编辑文本字段且没有正在编辑的文本字段时出现,以及当我需要隐藏键盘时(当用户在 iPad 上按下 DownKey 时)出现 DidEnd

有什么想法吗??

我试过这个:

if (scroll2.frame.origin.y != 414) {

...它可以工作,但是当我按重新运行键时,没有动画发生。

最佳答案

相关文本字段将其自身与参数一起发送给 textFieldDidBeginEditing。

添加 if () block 来测试 textField1 和 textField2 即:

-(void)textFieldDidBeginEditing:(UITextField *)textField {
if (textField == textField1) {
//do animation linked to textField1
}
if (textField == textField2) {
//do animation linked to textField2
}
}

此外,您应该实现此方法

-(BOOL)textFieldShouldReturn:(UITextField *)textField {
//handles the enter/done key
//perform whatever action for when user touches return
if (textField == textField1) {
[textField2 becomeFirstResponder];
} else {
[textField1 becomeFirstResponder];
}
return YES or NO;
}

关于ios - 在第二次 UITextField 编辑时显示和隐藏键盘,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12320730/

36 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com