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 6556127
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T12:54:17+00:00 2026-05-25T12:54:17+00:00

i have used following code to move the screen upwards when we hit on

  • 0

i have used following code to move the screen upwards when we hit on text field ,,this code was working fine with xcode 3 but its not working with xcode 4 ,,its not giving any error but when we touch on the text field screen ill go upwards to a greater height ,,some times wont come back ti original position

- (void)keyboardWasShown:(NSNotification *)aNotification {
    if ( keyboardShown )
        return;

    if ((activeField==tfText[4])||(activeField==tfText[5]))
    {


#if __IPHONE_OS_VERSION_MIN_REQUIRED <= __IPHONE_3_2
        CGRect _keyboardEndFrame;

        [[aNotification.userInfo valueForKey:UIKeyboardBoundsUserInfoKey] getValue:&_keyboardEndFrame];
        CGFloat keyboardSize;
        if ([[UIDevice currentDevice] orientation] == UIDeviceOrientationPortrait || [[UIDevice currentDevice] orientation] == UIDeviceOrientationPortraitUpsideDown) 
        {
            keyboardSize = _keyboardEndFrame.size.height;
        }
        else {
            keyboardSize = _keyboardEndFrame.size.width;
        }

        NSTimeInterval animationDuration = 0.300000011920929;
        CGRect frame = self.view.frame;
        frame.origin.y -= keyboardSize-70;
        frame.size.height += keyboardSize-70;
        [UIView beginAnimations:@"ResizeForKeyboard" context:nil];
        [UIView setAnimationDuration:animationDuration];
        self.view.frame = frame;
        [UIView commitAnimations];
#else
        NSDictionary *info = [aNotification userInfo];
        NSValue *aValue = [info objectForKey:UIKeyboardBoundsUserInfoKey];
        CGSize keyboardSize = [aValue CGRectValue].size;

        NSTimeInterval animationDuration = 0.300000011920929;
        CGRect frame = self.view.frame;
        frame.origin.y -= keyboardSize.height-70;
        frame.size.height += keyboardSize.height-70;
        [UIView beginAnimations:@"ResizeForKeyboard" context:nil];
        [UIView setAnimationDuration:animationDuration];
        self.view.frame = frame;
        [UIView commitAnimations];





#endif

        viewMoved = YES;
    }

    keyboardShown = YES;
}


- (void)keyboardWasHidden:(NSNotification *)aNotification {
    if ( viewMoved ) {

#if __IPHONE_OS_VERSION_MIN_REQUIRED <= __IPHONE_3_2
        CGRect _keyboardEndFrame;
        [[aNotification.userInfo valueForKey:UIKeyboardBoundsUserInfoKey] getValue:&_keyboardEndFrame];
        CGFloat keyboardSize;
        if ([[UIDevice currentDevice] orientation] == UIDeviceOrientationPortrait || [[UIDevice currentDevice] orientation] == UIDeviceOrientationPortraitUpsideDown) {
            keyboardSize = _keyboardEndFrame.size.height;
        }
        else {
            keyboardSize = _keyboardEndFrame.size.width;
        }

        NSTimeInterval animationDuration = 0.300000011920929;
        CGRect frame = self.view.frame;
        frame.origin.y += keyboardSize-70;
        frame.size.height -= keyboardSize-70;
        [UIView beginAnimations:@"ResizeForKeyboard" context:nil];
        [UIView setAnimationDuration:animationDuration];
        self.view.frame = frame;
        [UIView commitAnimations];
#else
        NSValue *aValue = [info objectForKey:UIKeyboardBoundsUserInfoKey];
        CGSize keyboardSize = [aValue CGRectValue].size;

        NSTimeInterval animationDuration = 0.300000011920929;
        CGRect frame = self.view.frame;
        frame.origin.y += keyboardSize.height-70;
        frame.size.height -= keyboardSize.height-70;
        [UIView beginAnimations:@"ResizeForKeyboard" context:nil];
        [UIView setAnimationDuration:animationDuration];
        self.view.frame = frame;
        [UIView commitAnimations];



#endif

        viewMoved = NO;
    }

    keyboardShown = NO;
}

- (void)textFieldDidBeginEditing:(UITextField *)textField 
{
    activeField = textField;
}


- (void)textFieldDidEndEditing:(UITextField *)textField 
{
    activeField = nil;
    // Additional Code
}

using following code i am calling the above methods

- (void)viewDidLoad 
{
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(keyboardWasShown:)
                                                 name:UIKeyboardDidShowNotification
                                               object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(keyboardWasHidden:)
                                                 name:UIKeyboardDidHideNotification
                                               object:nil];
}
  • 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-05-25T12:54:18+00:00Added an answer on May 25, 2026 at 12:54 pm
    - (void)viewDidLoad 
    {
        [super viewDidLoad];
    
    // register for keyboard notifications
    [[NSNotificationCenter defaultCenter] addObserver:self 
                                             selector:@selector(keyboardWillShow:) 
                                                 name:UIKeyboardWillShowNotification 
                                               object:self.view.window];
    // register for keyboard notifications
    [[NSNotificationCenter defaultCenter] addObserver:self 
                                             selector:@selector(keyboardWillHide:) 
                                                 name:UIKeyboardWillHideNotification 
                                               object:self.view.window];
        keyboardIsShown = NO;
            //make contentSize bigger than your scrollSize (you will need to figure out for your own use case)
        CGSize scrollContentSize = CGSizeMake(320, 345);
        self.scrollView.contentSize = scrollContentSize;
        }
    
    
    - (void)viewDidUnload {
        // Release any retained subviews of the main view.
        // e.g. self.myOutlet = nil;
    
        // unregister for keyboard notifications while not visible.
        [[NSNotificationCenter defaultCenter] removeObserver:self 
                                                        name:UIKeyboardWillShowNotification 
                                                      object:nil]; 
        // unregister for keyboard notifications while not visible.
        [[NSNotificationCenter defaultCenter] removeObserver:self 
                                                        name:UIKeyboardWillHideNotification 
                                                      object:nil];  
    
    }
    
    - (void)keyboardWillHide:(NSNotification *)n
    {
        NSDictionary* userInfo = [n userInfo];
    
        // get the size of the keyboard
        NSValue* boundsValue = [userInfo objectForKey:UIKeyboardBoundsUserInfoKey];
        CGSize keyboardSize = [boundsValue CGRectValue].size;
    
    
        // resize the scrollview
        CGRect viewFrame = self.scrollView.frame;
        // I'm also subtracting a constant kTabBarHeight because my UIScrollView was offset by the UITabBar so really only the portion of the keyboard that is leftover pass the UITabBar is obscuring my UIScrollView.
        viewFrame.size.height += (keyboardSize.height - kTabBarHeight);
    
        [UIView beginAnimations:nil context:NULL];
        [UIView setAnimationBeginsFromCurrentState:YES];
        // The kKeyboardAnimationDuration I am using is 0.3
        [UIView setAnimationDuration:kKeyboardAnimationDuration];
        [self.scrollView setFrame:viewFrame];
        [UIView commitAnimations];
    
        keyboardIsShown = NO;
    }
    
    - (void)keyboardWillShow:(NSNotification *)n
    {
        // This is an ivar I'm using to ensure that we do not do the frame size adjustment on the UIScrollView if the keyboard is already shown.  This can happen if the user, after fixing editing a UITextField, scrolls the resized UIScrollView to another UITextField and attempts to edit the next UITextField.  If we were to resize the UIScrollView again, it would be disastrous.  NOTE: The keyboard notification will fire even when the keyboard is already shown.
        if (keyboardIsShown) {
            return;
        }
    
        NSDictionary* userInfo = [n userInfo];
    
        // get the size of the keyboard
        NSValue* boundsValue = [userInfo objectForKey:UIKeyboardBoundsUserInfoKey];
        CGSize keyboardSize = [boundsValue CGRectValue].size;
    
        // resize the noteView
        CGRect viewFrame = self.scrollView.frame;
        // I'm also subtracting a constant kTabBarHeight because my UIScrollView was offset by the UITabBar so really only the portion of the keyboard that is leftover pass the UITabBar is obscuring my UIScrollView.
        viewFrame.size.height -= (keyboardSize.height - kTabBarHeight);
    
        [UIView beginAnimations:nil context:NULL];
        [UIView setAnimationBeginsFromCurrentState:YES];
        // The kKeyboardAnimationDuration I am using is 0.3
        [UIView setAnimationDuration:kKeyboardAnimationDuration];
        [self.scrollView setFrame:viewFrame];
        [UIView commitAnimations];
    
        keyboardIsShown = YES;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have used following code to create a simple PDF file. It executes fine
I have used following code to add three variables but instead of adding these
i have used following code to repeat a process creation/close iteratively dim vProcessInfo as
I have used the following code in a number of applications to load .DLL
i have used the following code in .htaccess Options +FollowSymlinks RewriteEngine On RewriteBase /
I have the following code - it is used to load a drop down
I have used the code supplied in the following CodeProject article in the past
I have the following code in an Autofac Module that is used in my
I have used following code for retrieving content from a csv file. <?php $fo
I have used the following code several times before, and have recently found it

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.