keyboards hide entering text - iphone

I am working on QuickDialog at here
However, my view can not scroll and the keyboard is hiding the entering text. What I am having so far is
- (void)loadView {
self.navigationController.navigationBarHidden = NO;
self.navigationController.navigationBar.tintColor = [UIColor blackColor];
self.navigationItem.hidesBackButton = NO;
NSLog(#"LOAD VIEW");
self.root = [[QRootElement alloc] init] ;
self.root.controllerName = #"CreateAccountViewController";
self.root.grouped = YES;
self.root.title = #"Registration";
[super loadView];
QSection *section1 = [[QSection alloc] init];
// Create title cell
QEntryElement *cell1 = [[QEntryElement alloc] init];
cell1.title = #"Title: ";
cell1.key = #"title";
cell1.placeholder = #"Mr/Mrs/Miss";
cell1.hiddenToolbar = YES;
cell1.autocapitalizationType = UITextAutocapitalizationTypeNone;
cell1.autocorrectionType = UITextAutocorrectionTypeNo;
// Create firstName cell
QEntryElement *cell2 = [[QEntryElement alloc] init];
cell2.title = #"FirstName: ";
cell2.key = #"firstName";
cell2.placeholder = #"Enter your first name";
cell2.hiddenToolbar = YES;
cell2.autocapitalizationType = UITextAutocapitalizationTypeNone;
cell2.autocorrectionType = UITextAutocorrectionTypeNo;
// Create lastName cell
QEntryElement *cell3 = [[QEntryElement alloc] init];
cell3.title = #"LastName: ";
cell3.key = #"lastName";
cell3.placeholder = #"Enter your last name";
cell3.hiddenToolbar = YES;
cell3.autocapitalizationType = UITextAutocapitalizationTypeNone;
cell3.autocorrectionType = UITextAutocorrectionTypeNo;
// Create phone number cell
QEntryElement *cell4 = [[QEntryElement alloc] init];
cell4.title = #"Phone: ";
cell4.key = #"phoneNumber";
cell4.placeholder = #"Enter your phone number";
cell4.hiddenToolbar = YES;
cell4.autocapitalizationType = UITextAutocapitalizationTypeNone;
cell4.autocorrectionType = UITextAutocorrectionTypeNo;
.............................
.............................
[main addElement:cell1];
[main addElement:cell2];
[main addElement:cell3];
[main addElement:cell4];
[main addElement:cell5];
[main addElement:cell6];
[main addElement:cell7];
[self.root addSection:section];
After running it, i realized that the keyboard is hiding the context because I have a long list of input. Also, the view is not scrollable at all
There are an attached image at here that you can see my problem...
![enter image description here][3]
I went thru the sample code and the view is scrollable so that the keyboard is not going to hide any text at all.
Does any body have any ideas about this issue, please help. All comments are welcomed here

Just for this record, since this question was asked, this has been implemented in QuickDialog, so you don't have to worry about it anymore.

One way to solve this problem is to resize the scroll view to [screen height] - [height of keyboard] (this is coming from a similar post that I saw somewhere).
You might want to try that.

There are 2 possible ways.
To change the view height when keyboard opens or closes.
To change the view origin when keyboard opens or closes.

Implementing this code in the two delegate methods of your textField will do what you want. Here is the textFieldDidBeginEditing:
- (void)textFieldDidBeginEditing:(UITextField *)textField
{
CGRect textFieldRect =
[self.view.window convertRect:textField.bounds fromView:textField];
CGRect viewRect =
[self.view.window convertRect:self.view.bounds fromView:self.view];
CGFloat midline = textFieldRect.origin.y + 0.5 * textFieldRect.size.height;
CGFloat numerator =
midline - viewRect.origin.y
- MINIMUM_SCROLL_FRACTION * viewRect.size.height;
CGFloat denominator =
(MAXIMUM_SCROLL_FRACTION - MINIMUM_SCROLL_FRACTION)
* viewRect.size.height;
CGFloat heightFraction = numerator / denominator;
if (heightFraction < 0.0)
{
heightFraction = 0.0;
}
else if (heightFraction > 1.0)
{
heightFraction = 1.0;
}
UIInterfaceOrientation orientation =
[[UIApplication sharedApplication] statusBarOrientation];
if (orientation == UIInterfaceOrientationPortrait ||
orientation == UIInterfaceOrientationPortraitUpsideDown)
{
animatedDistance = floor(PORTRAIT_KEYBOARD_HEIGHT * heightFraction);
}
else
{
animatedDistance = floor(LANDSCAPE_KEYBOARD_HEIGHT * heightFraction);
}
CGRect viewFrame = self.view.frame;
viewFrame.origin.y -= animatedDistance;
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationBeginsFromCurrentState:YES];
[UIView setAnimationDuration:KEYBOARD_ANIMATION_DURATION];
[self.view setFrame:viewFrame];
[UIView commitAnimations];
}
And here is the textFieldDidEndEditing:
- (void)textFieldDidEndEditing:(UITextField *)textField
{
CGRect viewFrame = self.view.frame;
viewFrame.origin.y += animatedDistance;
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationBeginsFromCurrentState:YES];
[UIView setAnimationDuration:KEYBOARD_ANIMATION_DURATION];
[self.view setFrame:viewFrame];
[self textFieldShouldReturn:textField];
[UIView commitAnimations];
}
If you want it for the buttons you can just setup an IBAction with the above code.

Related

UITextView strange behavior

Okay I'm lost here.
So have this UIViewController we can call it viewController1 where I add a new editable UITextView for every click on an add button.
I then use UIPanGestureRecognizer so you can drag them where ever you want. This works just fine. Now I want to go to viewController2: [self.navigationController pushViewController:viewController2 animated:YES]; but when I press the back button to return to viewController1 the first UITextView that was created in viewController1 has changed. It's not gone but the text property inside the textview has moved.
This just happens for the first instance of UITextView that I create, any ideas here would be appreciated.
Here's my method for creating the text:
-(void)addTextFieldToScreen
{
UITextView *textView = [[UITextView alloc]initWithFrame:CGRectMake(10, 80, 140, 120)];
textView.text = #"TEXT";
textView.backgroundColor = [UIColor clearColor];
textView.textColor = [UIColor purpleColor];
textView.font = [UIFont fontWithName:#"AmericanTypewriter" size:30];
textView.userInteractionEnabled = YES;
UIPanGestureRecognizer *panRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:#selector(moveText:)];
panRecognizer.minimumNumberOfTouches = 1;
panRecognizer.maximumNumberOfTouches = 1;
panRecognizer.delegate = self;
[textView addGestureRecognizer:panRecognizer];
[self.view addSubview:textView];
}
And here's my method for making my textView dragable:
-(void)moveText:(id)sender {
[[[(UITapGestureRecognizer*)sender view] layer] removeAllAnimations];
[self.view bringSubviewToFront:[(UIPanGestureRecognizer*)sender view]];
CGPoint translatedPoint = [(UIPanGestureRecognizer*)sender translationInView:self.view];
if([(UIPanGestureRecognizer*)sender state] == UIGestureRecognizerStateBegan) {
firstX = [[sender view] center].x;
firstY = [[sender view] center].y;
}
translatedPoint = CGPointMake(firstX+translatedPoint.x, firstY+translatedPoint.y);
[[sender view] setCenter:translatedPoint];
if([(UIPanGestureRecognizer*)sender state] == UIGestureRecognizerStateEnded) {
CGFloat finalX = translatedPoint.x + (.35*[(UIPanGestureRecognizer*)sender velocityInView:self.view].x);
CGFloat finalY = translatedPoint.y + (.35*[(UIPanGestureRecognizer*)sender velocityInView:self.view].y);
CGRect screenRect = [[UIScreen mainScreen] bounds];
CGFloat workingWidth = screenRect.size.width - 40;
CGFloat workingHeight = screenRect.size.height - 80;
if(finalX < 50) {
finalX = 50;
}
else if(finalX > workingWidth ) {
finalX = workingWidth;
}
if(finalY < 80) {
finalY = 80;
}
else if(finalY > workingHeight) {
finalY = workingHeight;
}
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationCurve:UIViewAnimationCurveLinear];
[UIView setAnimationDuration:.20];
[UIView commitAnimations];
}
}
EDIT:
Okay here's whats going on, I add two textviews with content "TEXT" with the "add text" button in the right corner in viewController1:
And then when I come back from viewController2 to viewController1 this is what I see:
As you can see it's only the left textView instance text property that change position, and this is the first one I'm adding.

Move keyboard up on editing uitextfield

I have an UITextField at the top of the UIScrollView while on editing I can't see the keyboard. How to do that?
Help me out with this, thanks in advance.
-(void)viewdidload{
txtsearch =[[UITextField alloc]init];
[txtsearch setFrame:CGRectMake(410, 35,250, 30)];
[txtsearch setBorderStyle:UITextBorderStyleRoundedRect];
txtsearch.placeholder = #"Enter Company/Provider Name";
txtsearch.text=[NSString stringWithFormat:#"%#",appDelegate.searchFieldName];
txtsearch.autocorrectionType = UITextAutocorrectionTypeNo;
txtsearch.font = [UIFont fontWithName:#"Helvetica" size:14];
txtsearch.delegate=self;
txtsearch.clearButtonMode = UITextFieldViewModeWhileEditing;
[testscroll addSubview:txtsearch];
btnSearch = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[btnSearch addTarget:self
action:#selector(showResults:)
forControlEvents:UIControlEventTouchDown];
[btnSearch setBackgroundImage:[UIImage imageNamed:#"search_button_hover.png"] forState:UIControlStateNormal];
btnSearch.frame = CGRectMake(510, 80, 75, 35.0);
[testscroll addSubview:btnSearch];
if(self.tableView)
[self.tableView removeFromSuperview];
self.tableView=[[UITableView alloc] initWithFrame:CGRectMake(0,210,730,[arr count]*160) style:UITableViewStylePlain];
self.tableView.delegate=self;
self.tableView.dataSource=self;
self.tableView.scrollEnabled = NO;
[testscroll addSubview:self.tableView];
[self.tableView reloadData];
self.tableView.frame = CGRectMake(self.tableView.frame.origin.x, self.tableView.frame.origin.y, self.tableView.frame.size.width, self.tableView.contentSize.height);
float ftbl = self.tableView.frame.origin.y + self.tableView.contentSize.height + 30;
testscroll.contentSize=CGSizeMake(768, ftbl);
testscroll.scrollEnabled=YES;
}
In your .h file add :
CGFloat animatedDistance;
In .m file : Add this before #interface declaration
static const CGFloat KEYBOARD_ANIMATION_DURATION = 0.3;
static const CGFloat MINIMUM_SCROLL_FRACTION = 0.2;
static const CGFloat MAXIMUM_SCROLL_FRACTION = 0.8;
static const CGFloat PORTRAIT_KEYBOARD_HEIGHT = 264;
static const CGFloat LANDSCAPE_KEYBOARD_HEIGHT = 352;
And add this UITextField delegate methods :
- (void)textFieldDidBeginEditing:(UITextField *)textField
{
CGRect textFieldRect =
[self.view.window convertRect:textField.bounds fromView:textField];
CGRect viewRect =
[self.view.window convertRect:self.view.bounds fromView:self.view];
CGFloat midline = textFieldRect.origin.y + 0.5 * textFieldRect.size.height;
CGFloat numerator = midline - viewRect.origin.y - MINIMUM_SCROLL_FRACTION * viewRect.size. height;
CGFloat denominator =
(MAXIMUM_SCROLL_FRACTION - MINIMUM_SCROLL_FRACTION) * viewRect.size.height;
CGFloat heightFraction = numerator / denominator;
if (heightFraction < 0.0)
{
heightFraction = 0.0;
}
else if (heightFraction > 1.0)
{
heightFraction = 1.0;
}
UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];
if (orientation == UIInterfaceOrientationPortrait ||
orientation == UIInterfaceOrientationPortraitUpsideDown)
{
animatedDistance = floor(PORTRAIT_KEYBOARD_HEIGHT * heightFraction);
}
else
{
animatedDistance = floor(LANDSCAPE_KEYBOARD_HEIGHT * heightFraction);
}
CGRect viewFrame = self.view.frame;
viewFrame.origin.y -= animatedDistance;
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationBeginsFromCurrentState:YES];
[UIView setAnimationDuration:KEYBOARD_ANIMATION_DURATION];
[yourScrollView setFrame:viewFrame];
[UIView commitAnimations];
}
- (void)textFieldDidEndEditing:(UITextField *)textField
{
CGRect viewFrame = self.view.frame;
viewFrame.origin.y += animatedDistance;
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationBeginsFromCurrentState:YES];
[UIView setAnimationDuration:KEYBOARD_ANIMATION_DURATION];
[yourScrollView setFrame:viewFrame];
[UIView commitAnimations];
}
Also, you can use TPKeyboardAvoiding.
Do like this,
- (void)textFieldDidBeginEditing:(UITextField *)textField
{
[self animateTextField:textField up:YES];
}
- (void)textFieldDidEndEditing:(UITextField *)textField
{
[self animateTextField:textField up:NO];
}
- (void) animateTextField: (UITextField*) textField up: (BOOL) up
{
CGPoint temp = [textField.superview convertPoint:textField.frame.origin toView:nil];
UIInterfaceOrientation orientation =
[[UIApplication sharedApplication] statusBarOrientation];
if (orientation == UIInterfaceOrientationPortrait){
if(up) {
int moveUpValue = temp.y+textField.frame.size.height;
animatedDis = 264-(1024-moveUpValue-5);
}
}
else if(orientation == UIInterfaceOrientationPortraitUpsideDown) {
if(up) {
int moveUpValue = 1004-temp.y+textField.frame.size.height;
animatedDis = 264-(1004-moveUpValue-5);
}
}
else if(orientation == UIInterfaceOrientationLandscapeLeft) {
if(up) {
int moveUpValue = temp.x+textField.frame.size.height;
animatedDis = 352-(768-moveUpValue-5);
}
}
else
{
if(up) {
int moveUpValue = 768-temp.x+textField.frame.size.height;
animatedDis = 352-(768-moveUpValue-5);
}
}
if(animatedDis>0)
{
const int movementDistance = animatedDis;
const float movementDuration = 0.3f;
int movement = (up ? -movementDistance : movementDistance);
[UIView beginAnimations: nil context: nil];
[UIView setAnimationBeginsFromCurrentState: YES];
[UIView setAnimationDuration: movementDuration];
if (orientation == UIInterfaceOrientationPortrait){
baseViewController.view.frame = CGRectOffset(baseViewController.view.frame, 0, movement);
}
else if(orientation == UIInterfaceOrientationPortraitUpsideDown) {
baseViewController.view.frame = CGRectOffset(baseViewController.view.frame, 0, movement);
}
else if(orientation == UIInterfaceOrientationLandscapeLeft) {
baseViewController.view.frame = CGRectOffset(baseViewController.view.frame, 0, movement);
}
else {
baseViewController.view.frame = CGRectOffset(baseViewController.view.frame, 0, movement);
}
[UIView commitAnimations];
}
}
Refer:
how move view up when keyboard appears in iPad?

Multiple UITextFields with UIPicker and UIKeyboard

So I have about 7 textfields and 6 of them use a keyboard and the other uses a picker. The problem I'm having is that if the keyboard is open when the textfield that is linked to the picker is touched the keyboard won't dismiss and the picker appears under it. Here's my code
- (void) textFieldDidBeginEditing:(UITextField *)textField
{
pickerView.hidden = YES;
if ([textField isEqual:state])
{
[state resignFirstResponder];
[self textFieldFirstResponderOnDelay1];
}
else
{
pickerView.hidden = YES;
// This movie the view up so textfield isn't hidden by keyboard
CGRect textFieldRect =
[self.view.window convertRect:textField.bounds fromView:textField];
CGRect viewRect =
[self.view.window convertRect:self.view.bounds fromView:self.view];
CGFloat midline = textFieldRect.origin.y + 0.5 * textFieldRect.size.height;
CGFloat numerator =
midline - viewRect.origin.y
- MINIMUM_SCROLL_FRACTION * viewRect.size.height;
CGFloat denominator =
(MAXIMUM_SCROLL_FRACTION - MINIMUM_SCROLL_FRACTION)
* viewRect.size.height;
CGFloat heightFraction = numerator / denominator;
if (heightFraction < 0.0)
{
heightFraction = 0.0;
}
else if (heightFraction > 1.0)
{
heightFraction = 1.0;
}
UIInterfaceOrientation orientation =
[[UIApplication sharedApplication] statusBarOrientation];
if (orientation == UIInterfaceOrientationPortrait ||
orientation == UIInterfaceOrientationPortraitUpsideDown)
{
animatedDistance = floor(PORTRAIT_KEYBOARD_HEIGHT * heightFraction);
}
else
{
animatedDistance = floor(LANDSCAPE_KEYBOARD_HEIGHT * heightFraction);
}
CGRect viewFrame = self.view.frame;
viewFrame.origin.y -= animatedDistance;
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationBeginsFromCurrentState:YES];
[UIView setAnimationDuration:KEYBOARD_ANIMATION_DURATION];
[self.view setFrame:viewFrame];
[UIView commitAnimations];
}
}
-(void) viewDidLoad
{
pickerView = [[UIPickerView alloc] init];
pickerView.frame = CGRectMake(0, 245, 320, 216);
pickerView.delegate = self;
pickerView.hidden = YES;
pickerView.showsSelectionIndicator = YES;
state.inputView = pickerView;
[self.view addSubview:pickerView];
}
-(void)textFieldFirstResponderOnDelay1
{
pickerView.hidden=NO;
[pickerView reloadAllComponents];
}
- (void)textFieldDidEndEditing:(UITextField *)textField
{
if([textField isEqual:state])
{
}
else
{
CGRect viewFrame = self.view.frame;
viewFrame.origin.y += animatedDistance;
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationBeginsFromCurrentState:YES];
[UIView setAnimationDuration:KEYBOARD_ANIMATION_DURATION];
[self.view setFrame:viewFrame];
[UIView commitAnimations];
}
}
Instead of adding the pickerview as a subview of your main window, just set it as the input view for the appropriate textviews, then it will show/hide as the keyboard would normally:
textField.inputView = pickerView;

Trigger done button touch in iPhone

How can i trigger done button touch in iPhone?
I have an asynchronous task which pops me small tableView (adds it to subView). When one of my textFields is focused - keyboard is shown and overlays my tableView.
I tried to call resignFirstResponder on focused textField in "textFieldShouldBeginEditing" and it didn't help. So i think maybe explicit trigger of done button will work.
You can animate the entire frame of the view whenever the textfield is focused, so that it slides up and display the table and also the textfield without any hindrance.
you could have the done button as right navigation button of your view controller.
UIBarButtonItem *doneButton = [[UIBarButtonItem alloc] initWithTitle:#"Done" style:UIBarButtonItemStylePlain target:self action:#selector(doneButtonPressed:)];
self.navigationItem.rightBarButtonItem = doneButton ;
[doneButton release];
Implement doneButtonPressed: method as below.
-(void) doneButtonPressed:(id) sender
{
[myTextField resignFirstResponder];
}
If you don't want the text field to becomeFirstResponder or to be edited, return NO from textFieldShouldBeginEditing method.
What I understood from your question that your other fields get hided when you enter in the textfield.For this you need to animate the view.I am going to put the code for this for you.
In your header file declare this.
CGFloat animatedDistance;
And in your .m file put this code and you won't face any problem.Your view will automatically scroll up and down when you start editing the text fields so making the space to view your fields properly..
#pragma mark -
#pragma mark (Text Field Delegate Method)
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
[textField resignFirstResponder];
return YES;
}
-(void)textFieldDidBeginEditing:(UITextField *)textField
{
static const CGFloat KEYBOARD_ANIMATION_DURATION = 0.3;
static const CGFloat MINIMUM_SCROLL_FRACTION = 0.2;
static const CGFloat MAXIMUM_SCROLL_FRACTION = 0.8;
static const CGFloat PORTRAIT_KEYBOARD_HEIGHT = 216;
static const CGFloat LANDSCAPE_KEYBOARD_HEIGHT = 162;
CGRect textFieldRect;
CGRect viewRect;
textFieldRect =[addProScrollView.window convertRect:textField.bounds fromView:textField];
viewRect =[addProScrollView.window convertRect:addProScrollView.bounds fromView:addProScrollView];
CGFloat midline = textFieldRect.origin.y + 0.5 * textFieldRect.size.height;
CGFloat numerator = midline - viewRect.origin.y - MINIMUM_SCROLL_FRACTION * viewRect.size.height;
CGFloat denominator = (MAXIMUM_SCROLL_FRACTION - MINIMUM_SCROLL_FRACTION) * viewRect.size.height;
CGFloat heightFraction = numerator / denominator;
if (heightFraction < 0.0)
{
heightFraction = 0.0;
}
else if (heightFraction > 1.0)
{
heightFraction = 1.0;
}
UIInterfaceOrientation orientation =[[UIApplication sharedApplication] statusBarOrientation];
if (orientation == UIInterfaceOrientationPortrait ||orientation == UIInterfaceOrientationPortraitUpsideDown)
{
animatedDistance = floor(PORTRAIT_KEYBOARD_HEIGHT * heightFraction);
}
else
{
animatedDistance = floor(LANDSCAPE_KEYBOARD_HEIGHT * heightFraction);
}
CGRect viewFrame;
viewFrame= addProScrollView.frame;
viewFrame.origin.y -= animatedDistance;
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationBeginsFromCurrentState:YES];
[UIView setAnimationDuration:KEYBOARD_ANIMATION_DURATION];
[addProScrollView setFrame:viewFrame];
[UIView commitAnimations];
}
-(void)textFieldDidEndEditing:(UITextField *)textField
{
if(textField.tag==0)
{
static const CGFloat KEYBOARD_ANIMATION_DURATION = 0.3;
CGRect viewFrame;
viewFrame= addProScrollView.frame;
viewFrame.origin.y += animatedDistance;
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationBeginsFromCurrentState:YES];
[UIView setAnimationDuration:KEYBOARD_ANIMATION_DURATION];
[addProScrollView setFrame:viewFrame];
[UIView commitAnimations];
}
}
Thats it .You are now done just run your code.
Cheers......

How to Drag my view a little bit up when keyboard comes up?

In my app i have some textfields which gets filled through the keyboard. There are 6 of them and the last two are in very bottom of the screen and it gets hidden whenever keyboard comes up.
Any suggestions??
Make the textFields delegate as self and add the following code to the textFieldDidBeginEditing and textFieldDidEndEditing.
Define the following constants: (the constants have been set for iPad. Tweak them for iphone)
static const CGFloat KEYBOARD_ANIMATION_DURATION = 0.3;
static const CGFloat MINIMUM_SCROLL_FRACTION = 0.2;
static const CGFloat MAXIMUM_SCROLL_FRACTION = 0.8;
static const CGFloat PORTRAIT_KEYBOARD_HEIGHT = 216;
static const CGFloat LANDSCAPE_KEYBOARD_HEIGHT = 302;
Add two variables in the .h file of your class. CGFloat animatedDistance; and UITextField *currentField;
- (void)textFieldDidBeginEditing:(UITextField *)textField {
currentField = textField;
UIInterfaceOrientation orientation =
[[UIApplication sharedApplication] statusBarOrientation];
CGRect textFieldRect =[self.view.window convertRect:textField.bounds fromView:textField];
CGRect viewRect =[self.view.window convertRect:self.view.bounds fromView:self.view];
if (orientation == UIInterfaceOrientationLandscapeLeft )
{
textFieldRect.origin.y = textFieldRect.origin.x;
textFieldRect.size.height = textFieldRect.size.width;
viewRect.size.height = viewRect.size.width;
}
else if (orientation == UIInterfaceOrientationLandscapeRight )
{
textFieldRect.origin.y =viewRect.size.width - textFieldRect.origin.x;
textFieldRect.size.height = textFieldRect.size.width;
viewRect.size.height = viewRect.size.width;
}
else if (orientation == UIInterfaceOrientationPortraitUpsideDown)
{
textFieldRect.origin.y = viewRect.size.height - textFieldRect.origin.y;
}
CGFloat midline = textFieldRect.origin.y + 0.5 * textFieldRect.size.height;
CGFloat numerator = midline - viewRect.origin.y - MINIMUM_SCROLL_FRACTION * viewRect.size.height;
CGFloat denominator =(MAXIMUM_SCROLL_FRACTION - MINIMUM_SCROLL_FRACTION)* viewRect.size.height;
CGFloat heightFraction = numerator / denominator;
if (heightFraction < 0.0)
{
heightFraction = 0.0;
}
else if (heightFraction > 1.0)
{
heightFraction = 1.0;
}
if (orientation == UIInterfaceOrientationPortrait ||
orientation == UIInterfaceOrientationPortraitUpsideDown)
{
animatedDistance = floor(PORTRAIT_KEYBOARD_HEIGHT * heightFraction);
}
else
{
animatedDistance = floor(LANDSCAPE_KEYBOARD_HEIGHT * heightFraction);
}
CGRect viewFrame = self.view.frame;
viewFrame.origin.y -= animatedDistance;
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationBeginsFromCurrentState:YES];
[UIView setAnimationDuration:KEYBOARD_ANIMATION_DURATION];
[self.view setFrame:viewFrame];
[UIView commitAnimations];
}
- (void)textFieldDidEndEditing:(UITextField *)textField {
[textField resignFirstResponder];
CGRect viewFrame = self.view.frame;
viewFrame.origin.y += animatedDistance;
animatedDistance = 0;
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationBeginsFromCurrentState:YES];
[UIView setAnimationDuration:KEYBOARD_ANIMATION_DURATION];
[self.view setFrame:viewFrame];
[UIView commitAnimations];
currentField = nil;
}
Use a UIScrollview so the user can scroll down. You can make use of the inputAccessoryView of a UITextField to show buttons like next and previous, on click let the input jump to the next textfield and scroll to it.
Have a look at this question and answers at SO, same problem, different solution.