Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8109095
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T01:18:52+00:00 2026-06-06T01:18:52+00:00

I have a form on the ipad which has many textfield and a button

  • 0

I have a form on the ipad which has many textfield and a button at the end. There are some fields which come under the keyboard when it is active. In order to pull the hidden texfield behind the keyboard to be visible I am using the following code.

- (void)textFieldDidBeginEditing:(UITextField *)textField
{
[self animateTextField:textField up:YES];
}

- (void)textFieldDidEndEditing:(UITextField *)textField
{
_scrollView.frame=CGRectMake(0, 0, 1024, 655);
[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)
{
    // NSLog(@"portrait");
    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);
        _scrollView.frame = CGRectMake(0, 0, 1024, 655-240);
    }

}
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)
    {
        self.view.frame = CGRectOffset(self.view.frame, 0, movement);
    }
    else if(orientation == UIInterfaceOrientationPortraitUpsideDown)
    {
        self.view.frame = CGRectOffset(self.view.frame, 0, movement);
    }
    else if(orientation == UIInterfaceOrientationLandscapeLeft)
    {
        self.view.frame = CGRectOffset(self.view.frame, 0, movement);
    }
    else
    {
        self.view.frame = CGRectOffset(self.view.frame, 0, movement);
    }
    [UIView commitAnimations];
}
}

I am also using the scroll view. My issue is that when the keyboard is active and i press my button it take me to the next screen. Now if i navigate back, the keyboard is active and the prior animations are set. Now if i hide the keyboard, the entire view scrolls down leaving a black portion on top. How to handle this situation?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T01:18:55+00:00Added an answer on June 6, 2026 at 1:18 am

    Okay. After much research I found a simple method. It is the use of notifications.
    In my viewDidLoad i added these two keyboard notifications.

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWasShown:) name: UIKeyboardDidShowNotification object:nil];
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillBeHidden:) name:UIKeyboardWillHideNotification object:nil];
    

    These are the 2 selector methods:

    -(void)keyboardWasShown:(NSNotification *)aNotification
    {
    
    if (displayKeyboard==YES) {
        return;
    }
    NSDictionary* info = [aNotification userInfo];
    NSValue* aValue = [info objectForKey:UIKeyboardBoundsUserInfoKey];
    //NSValue* aValue = [info objectForKey:UIKeyboardFrameBeginUserInfoKey];
    CGSize keyboardSize = [aValue CGRectValue].size;
    
    NSLog(@"kbw====%fkbh====%f",keyboardSize.width,keyboardSize.height);
    
    offset = _scrollView.contentOffset;
    
    CGRect viewFrame = _scrollView.frame;
    
    NSLog(@"svw====%fsvh===%f",viewFrame.size.width,viewFrame.size.height);
    viewFrame.size.height -= keyboardSize.height-49;
    NSLog(@"new view hgt =====%f",viewFrame.size.height);
    _scrollView.frame = viewFrame;
    
    CGRect textFieldRect = [activeField frame];
    textFieldRect.origin.y += 10;
    [_scrollView scrollRectToVisible: textFieldRect animated:YES];
    displayKeyboard = YES;
    }
    -(void)keyboardWillBeHidden:(NSNotification *)aNotification
    {
    
    if (!displayKeyboard) {
        return; 
    }
    
    _scrollView.frame = CGRectMake(0, 0, 1024, 655);
    _scrollView.contentOffset =offset;
    displayKeyboard = NO;
    }
    
    -(BOOL) textFieldShouldBeginEditing:(UITextField*)textField {
    activeField = textField;
    return YES;
    }
    

    displayKeyboard, offset and activeField are declared in .h file.

    Also remember to remove the notifications in viewDidDisappear:animated

    Although this method is quite different than the previous one stated, this one does not leave a black portion on the top while navigating between classes when the uikeyboard is active.

    Also what i noticed was if i used the deprecated UIKeyboardBoundsUserInfoKey i used to get the correct width and height of the keyboard(i am working only in landscape mode). Whereas when i used UIKeyboardFrameBeginUserInfoKey the width and height values were interchanged. I am still trying to figure out this problem.

    Also when the keyboard used to appear, a fixed space of 49px was appended to above it. I assumed that that was my tabbar height and therefore subtracted 49.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an iPad application which has a sign up form within it. The
I have form, where some fields are looks like rows, so I can add/delete
I have an iPad application in which I am displaying an input form as
I have a dynamic form that is to be displayed using an iPad. This
I have form with 1 button. when you click on the button 3 others
I have form with few buttons and I want to know what button is
I'm trying to create a form sheet modal on iPad, which should be a
I am developing an app for iphone/ipad that I have some problems with. I
I have designed a form which was working fine until about an hour ago.
Ultimately I have to send form post data from an iPad app to a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.