Iphone 在UITextField上帮助我
我有UITextFields的列表 在输入后,我想一个接一个地移动到下一个文本字段 因为键盘隐藏了字段 你们能告诉我怎么才能做到吗 非常感谢您抽出时间。Iphone 在UITextField上帮助我,iphone,iphone-sdk-3.0,Iphone,Iphone Sdk 3.0,我有UITextFields的列表 在输入后,我想一个接一个地移动到下一个文本字段 因为键盘隐藏了字段 你们能告诉我怎么才能做到吗 非常感谢您抽出时间。 (无效)shiftViewUp:(BOOL)向上 { [UIView beginAnimations:nil上下文:NULL] [UIView setAnimationDuration:0.3]; CGRect rect = self.view.frame; if (movedUp) { if(rect.origin.y == 0
- (无效)shiftViewUp:(BOOL)向上 {
[UIView setAnimationDuration:0.3];
CGRect rect = self.view.frame;
if (movedUp)
{
if(rect.origin.y == 0){
rect.origin.y -= 85.0;
rect.size.height += 85.0;
}
}
else
{
if(rect.origin.y != 0.0){
rect.origin.y += 85.0;
rect.size.height -= 85.0;
}
}
self.view.frame = rect;
[UIView commitAnimations];
}
基本上,您可以在开始编辑文本字段时使用BOOL YES调用此方法,在结束编辑时使用BOOL no调用此方法。
您只需跟踪正在编辑的文本字段,您可以根据该字段调整移位(如此处的85)- (无效)shiftViewUp:(BOOL)向上 {
[UIView setAnimationDuration:0.3];
CGRect rect = self.view.frame;
if (movedUp)
{
if(rect.origin.y == 0){
rect.origin.y -= 85.0;
rect.size.height += 85.0;
}
}
else
{
if(rect.origin.y != 0.0){
rect.origin.y += 85.0;
rect.size.height -= 85.0;
}
}
self.view.frame = rect;
[UIView commitAnimations];
}
基本上,您可以在开始编辑文本字段时使用BOOL YES调用此方法,在结束编辑时使用BOOL no调用此方法。
您只需要跟踪正在编辑的文本字段,您可以根据它调整移位(如这里的85)另一种方法是使用UITableView。然后大多数控件都准备好了。但你也可以自己实现这一切 首先将UITextfields放在单独的UIView上。使UIView成为一个正确连接的插座。这样,您可以轻松地通过动画向上移动文本字段 然后在委托方法中执行以下操作:
// Sets the label of the keyboard's return key to 'Done' when the insertion
// point moves to the table view's last field.
//
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
if ([textField tag] == myLastUITextField)
{
[textField setReturnKeyType:UIReturnKeyDone];
}
return YES;
}
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
if ([textField returnKeyType] != UIReturnKeyDone)
{
// If this is not the last field (in which case the keyboard's
// return key label will currently be 'Next' rather than 'Done'),
// just move the insertion point to the next field.
//
NSInteger nextTag = [textField tag] + 1;
UIView *nextTextField = [myTextView viewWithTag:nextTag];
// here starts your animation code
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.3];
CGRect rect = textFieldView.frame;
rect.origin.y = -44;
textFieldView.frame = rect;
[UIView commitAnimations];
// here ends your animation code. Play with it
[nextTextField becomeFirstResponder];
}
else
{
// do what you want to do with the last UITextfield
}
return YES;
}
`
我认为通过复制粘贴不会立即起作用,但我希望它指向一个方向。祝你好运另一种方法是使用UITableView。然后大多数控件都准备好了。但你也可以自己实现这一切 首先将UITextfields放在单独的UIView上。使UIView成为一个正确连接的插座。这样,您可以轻松地通过动画向上移动文本字段 然后在委托方法中执行以下操作:
// Sets the label of the keyboard's return key to 'Done' when the insertion
// point moves to the table view's last field.
//
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
if ([textField tag] == myLastUITextField)
{
[textField setReturnKeyType:UIReturnKeyDone];
}
return YES;
}
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
if ([textField returnKeyType] != UIReturnKeyDone)
{
// If this is not the last field (in which case the keyboard's
// return key label will currently be 'Next' rather than 'Done'),
// just move the insertion point to the next field.
//
NSInteger nextTag = [textField tag] + 1;
UIView *nextTextField = [myTextView viewWithTag:nextTag];
// here starts your animation code
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.3];
CGRect rect = textFieldView.frame;
rect.origin.y = -44;
textFieldView.frame = rect;
[UIView commitAnimations];
// here ends your animation code. Play with it
[nextTextField becomeFirstResponder];
}
else
{
// do what you want to do with the last UITextfield
}
return YES;
}
`
我认为通过复制粘贴不会立即起作用,但我希望它指向一个方向。祝你好运