如何向下滑动一个键盘向上滑动自定义一个
问题描述:
我在视图中有四个textField。 前三个用标准键盘编辑。 最后一个编辑器使用一个选择器作为textField的inputView属性。 这很酷,因为它处理幻灯片上下。如何向下滑动一个键盘向上滑动自定义一个
想象一下,我正在用标准键盘在前三个textField中的一个中输入内容。 现在我点击第四行。 我希望标准键盘缩回并使拾取器向上滑动。 现在它只是即时交换。
我试过使用textField委托方法在标准键盘上写入resignFirstResponder的逻辑,并成为使用选取器的第一响应者,但它仍然立即改变。这是代码。
- (void)textFieldDidBeginEditing:(UITextField *)textField{
//If we go from a keyboard field to a picker field
if ((self.textFieldBeingEdited == self.nameField || self.locationField || self.controllerSNField)){
if (textField == equipTypeField) {
//Put away the keyboard
[self.textFieldBeingEdited resignFirstResponder];
//Show the Picker
[textField becomeFirstResponder];
}
}
}
我还需要编写逻辑来选择器滑下向上滑动键盘,如果我从第四视图任何其他人去。但如果我能得到上半场,第二场应该很明显。
任何想法如何做到这一点,而不进入动画块?也许与通知?
谢谢。
答
问题可能是您已经开始编辑该方法的时间,因此resignFirstResponder
的调用不起作用,因为它不再是第一响应者。也许如果你再次成为第一响应者,它可能会奏效。但在equipTypeField
上调用becomeFirstResponder
可能会导致textFieldDidBeginEditing
再次被调用,从而导致您陷入无限循环。毫无疑问,窘境。但最起码,我会尝试这样的:
//So that the keyboard that animates out is the one that was previously showing
[self.textFieldBeingEdited becomeFirstResponder];
//Animate the keyboard out
[self.textFieldBeingEdited resignFirstResponder];
//Don't let the user screw anything up
[[UIApplication sharedApplication] beginIgnoringInteractionEvents];
//Animate the new keyboard in a little while later
[textField performSelector:@selector(becomeFirstResponder) withObject:nil afterDelay:0.25];
//Let the user interact with the application again after the animation completes
[[UIApplication sharedApplication] performSelector:@selector(endIgnoringInteractionEvents) withObject:nil afterDelay:0.25];
这仍然留下了哪里把这段代码的问题,因为如果你把它放在textFieldDidBeginEditing
,你可能会得到一个无限循环。我的建议是尝试一下,看看会发生什么。如果它工作,那么很好,否则,放入某种布尔标志或其他东西以确保在调用didFinishEditing之前只调用它一次。
它没有工作,但我从你的解决方案中学到了一两件事。我明白你对无限循环的含义。谢谢。 – Aaronium112 2011-01-29 14:35:26