I am new to iphone;
what i did is creating a 10 labels with corresponding text fields.
when i click on te开发者_Python百科xt field keypad is open.
But it covers the bottom 4 textfields.
I can't able to enter text to those fields.
i need when i click textfield in front of keypad screen moves up.
now i can able to enter in those textfields.
How can i done this.
Thank u in advance.
As Jumhyn wrote, make the UIViewController the delegate of all the text fields. Then assign the text fields tags from 0 to 9, from top to bottom. Then implement the following method in the controller:
- (void)textFieldDidEndEditing:(UITextField *)textField {
self.view.bounds = CGRectOffset(self.view.bounds, 0, textField.tag * 50);
[[self.view viewWithTag: textField.tag + 1] becomeFirstResponder];
}
The idea is that the first line shifts all the text fields up, depending on which text field has been edited, in the second line you activate the next text field. You will have to modify the code to better fit your layout, but it should give you the idea.
Make the UIViewController that handles the text views a UITextFieldDelegate:
@interface TextFieldViewController : UIViewController <UITextFieldDelegate> {
then in the textFieldShouldBeginEditing: method in the .m file, add the code that moves the text fields up. For example:
-(BOOL)textFieldShouldBeginEditing:(UITextField *)textField {
myTextField3.frame = CGRectMake(myTextField3.frame.origin.x, myTextField3.frame.origin.y - /*whatever you want to subtract from the y value*/, myTextField3.frame.size.width, myTextField3.frame.size.height);
myTextField4.frame = CGRectMake(myTextField4.frame.origin.x, myTextField4.frame.origin.y - /*whatever you want to subtract from the y value*/, myTextField4.frame.size.width, myTextField4.frame.size.height);
myTextField5.frame = CGRectMake(myTextField5.frame.origin.x, myTextField5.frame.origin.y - /*whatever you want to subtract from the y value*/, myTextField5.frame.size.width, myTextField5.frame.size.height);
myTextField6.frame = CGRectMake(myTextField6.frame.origin.x, myTextField6.frame.origin.y - /*whatever you want to subtract from the y value*/, myTextField6.frame.size.width, myTextField6.frame.size.height);
return YES;
}
精彩评论