0
我有10個UITextField'正在整個屏幕。當我想改變它們時,我在半屏上得到鍵盤,所以我不能改變'隱藏'字段。 有沒有人知道解決方案?小鍵盤隱藏UITextField
我有10個UITextField'正在整個屏幕。當我想改變它們時,我在半屏上得到鍵盤,所以我不能改變'隱藏'字段。 有沒有人知道解決方案?小鍵盤隱藏UITextField
您需要在調用鍵盤時向上移動框架。
- (void)keyboardWillShow:(NSNotification *)aNotification
{
self.frame = CGRectMake(0,-[size of keyboard],self.frame.size.width,self.frame.size.height);
}
- (void)textFieldDidBeginEditing:(UITextField *)textField {
if (textField == textField1) {
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDelegate:self];
[UIView setAnimationDuration:0.5];
[UIView setAnimationBeginsFromCurrentState:YES];
textfield1.frame = CGRectMake(textfield1.frame.origin.x, (textfield1.frame.origin.y - 100.0), textfield1.frame.size.width, textfield1.frame.size.height);
[UIView commitAnimations];
} else if (textField == textField2) {
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDelegate:self];
[UIView setAnimationDuration:0.5];
[UIView setAnimationBeginsFromCurrentState:YES];
textfield2.frame = CGRectMake(textfield2.frame.origin.x, (textfield2.frame.origin.y - 100.0), textfield2.frame.size.width, textfield2.frame.size.height);
[UIView commitAnimations];
}
}
- (void)textFieldDidEndEditing:(UITextField *)textField {
if (textField == textField1) {
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDelegate:self];
[UIView setAnimationDuration:0.5];
[UIView setAnimationBeginsFromCurrentState:YES];
textfield1.frame = CGRectMake(textfield1.frame.origin.x, (textfield1.frame.origin.y + 100.0), textfield1.frame.size.width, textfield1.frame.size.height);
[UIView commitAnimations];
} else if (textField == textField2) {
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDelegate:self];
[UIView setAnimationDuration:0.5];
[UIView setAnimationBeginsFromCurrentState:YES];
textfield2.frame = CGRectMake(textfield2.frame.origin.x, (textfield2.frame.origin.y + 100.0), textfield2.frame.size.width, textfield2.frame.size.height);
[UIView commitAnimations];
}
和觸摸:
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{ [文本字段resignFirstResponder]; }
希望能幫助你。
樂意提供幫助。
你可以有一個滾動視圖爲你的文本字段,每當你點擊文本字段時,鍵盤將出現。 – rishi 2012-04-22 11:49:07