我有3个UITexfield,用户可以填写前两个,但最后一个是类别字段,并在点击时显示UIPickerView。
到目前为止我设法做的是:
但是,当用户再次点击类别文本字段并显示选择器视图时,我知道我想要隐藏键盘。
这是我到目前为止所做的:
- (void)textFieldDidBeginEditing:(UITextField *)textField {
if(textField == categoryTextField){
[categoryTextField resignFirstResponder];
[UIView beginAnimations:@"picker" context:nil];
[UIView setAnimationDuration:0.3];
pickerView.transform = CGAffineTransformMakeTranslation(0,-236);
[UIView commitAnimations];
}else{
[UIView beginAnimations:@"picker" context:nil];
[UIView setAnimationDuration:0.3];
pickerView.transform = CGAffineTransformMakeTranslation(0,236);
[UIView commitAnimations];
}
}
但它不起作用。有什么想法?
答案 0 :(得分:2)
你太难了。将选择器视图设置为文本字段的输入视图,操作系统将为您处理动画。当每个字段成为第一响应者时,将显示相应的输入视图(文本的默认键盘,第三个的选择器)。您不需要自己动画。
答案 1 :(得分:0)
我真的不知道你的问题来自哪里。我想也许你的翻译让pickerView变得太过分了。你应该试试:
- (void)textFieldDidBeginEditing:(UITextField *)textField {
if(textField == categoryTextField){
[categoryTextField resignFirstResponder];
[UIView beginAnimations:@"picker" context:nil];
[UIView setAnimationDuration:0.3];
CGRect frame = pickerView.frame;
frame.origin.y = 480 - 236; // assuming your on an iPhone and your picker appears from bottom
pickerView.frame = frame;
[UIView commitAnimations];
}else{
[UIView beginAnimations:@"picker" context:nil];
[UIView setAnimationDuration:0.3];
CGRect frame = pickerView.frame;
frame.origin.y = 480; // assuming your on an iPhone and your picker disappears to bottom
pickerView.frame = frame;
[UIView commitAnimations];
}
}
希望有所帮助