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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T21:13:17+00:00 2026-06-08T21:13:17+00:00

I know this question has been asked a few times. I understand how to

  • 0

I know this question has been asked a few times. I understand how to move the view up or a textfield up when the keyboard is presented, however I am running into a glitch that I cannot seem to figure out.

The view I am trying to move up is inside a UIViewController that acts as a container for two views. This container is itself a view inside a sliding view controller (kind of like the one Facebook implements).

The text field moves up fine when you first load the view however if you go to a different view and come back, the keyboard causes the view to disappear.

Here is the code I am using to move the view up:

    - (void) animateTextField:(BOOL)up {

    const int movementDistance = 350; // tweak as needed
    const float movementDuration = 0; // tweak as needed

    int movement = (up ? -movementDistance : movementDistance);

    [UIView beginAnimations: @"anim" context: nil];
    [UIView setAnimationBeginsFromCurrentState: YES];
    [UIView setAnimationDuration: movementDuration];

    self.sendingToolbar.frame = CGRectOffset(self.sendingToolbar.frame, 0, movement);
    self.messagesTable.frame = CGRectOffset(self.messagesTable.frame, 0, movement);
    //[splitController moveViewUp:up];
    [UIView commitAnimations];

}

- (void)registerForKeyboardNotifications
{
    NSLog(@"was this method called");

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

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

}

// Called when the UIKeyboardDidShowNotification is sent.
- (void)keyboardWasShown:(NSNotification*)aNotification
{
    [self animateTextField:YES];
}
// Called when the UIKeyboardWillHideNotification is sent
- (void)keyboardWillBeHidden:(NSNotification*)aNotification
{
    [self animateTextField:NO];
}

Any ideas why this glitch might be happening? Thanks

After adding the suggestion for a boolean to check if the text field is already up the view disappears all the time when the keyboard is shown and not just when you leave the view and come back. Here is the revised method:

- (void) animateTextField:(BOOL)up {

    const int movementDistance = 350; // tweak as needed
    const float movementDuration = 0; // tweak as needed

    int movement = movementDistance;

    [UIView beginAnimations: @"anim" context: nil];
    [UIView setAnimationBeginsFromCurrentState: YES];
    [UIView setAnimationDuration: movementDuration];

    if(textFieldIsUp && (up == YES)) {
        NSLog(@"Case 1");
        // Do nothing since text field is already up
    }
    else if(textFieldIsUp && (up == NO)) {
        NSLog(@"Case 2");
        // Move the text field down
        self.sendingToolbar.frame = CGRectOffset(self.sendingToolbar.frame, 0, -movement);
        self.messagesTable.frame = CGRectOffset(self.messagesTable.frame, 0, -movement);

        textFieldIsUp = NO;
    }
    else if((textFieldIsUp == NO) && (up == YES)) {
        NSLog(@"Case 3");
        // Move the text field up
        self.sendingToolbar.frame = CGRectOffset(self.sendingToolbar.frame, 0, movement);
        self.messagesTable.frame = CGRectOffset(self.messagesTable.frame, 0, movement);

        textFieldIsUp = YES;
    }
    else if((textFieldIsUp == NO) && (up == NO)) {
        NSLog(@"Case 4");
        // Do nothing since the text field is already down
    }
    else {
        NSLog(@"Default");
        // Default catch all case. Does nothing
    }

    [UIView commitAnimations];

}

Here are some more details about my setup:

The view controller is a messaging center for the app. The view controller contains two subviews the subview on the left side is a menu for picking the conversation and the right menu is a subview with the messages within that conversation. Since I want the messages to load from the bottom up, the table view is rotated 180 degrees and the cells are also rotated 180 degrees the opposite direction. Also the table view reloads every 5 seconds using an NSTimer so that the messages can be updated with any new messages.

  • 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-08T21:13:18+00:00Added an answer on June 8, 2026 at 9:13 pm

    The textfield has already been moved up but didn’t move back down when you left the view. When you revisit the view it gets moved up again – and off the screen.

    I’ve had this problem before; solved it by keeping a boolean variable the indicated whether the textfield was in the up or down position. Check the variable to make sure the textfield isn’t already up before you move it up again.

    How I did it. I’m using an NSNumber property on my view to store whether the view has been pushed up or not so that other views can communicate whether they have pushed the view up or down.

    //In viewDidLoad
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardDidShow:) name:UIKeyboardWillShowNotification object:nil];
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardDidHide:) name:UIKeyboardWillHideNotification object:nil];
    
    //Pushes the view up if one of the table forms is selected for editing
    - (void) keyboardDidShow:(NSNotification *)aNotification
    {
        if ([isRaised boolValue] == NO)
        {
            [UIView beginAnimations:nil context:NULL];
            [UIView setAnimationDuration:0.25];
            self.view.center = CGPointMake(self.view.center.x, self.view.center.y-moveAmount);
            [UIView commitAnimations];
            isRaised = [NSNumber numberWithBool:YES];
        }
    }
    
    //Push view back down
    - (void) keyboardDidHide:(NSNotification *)aNotification
    {
        if ([isRaised boolValue])
        {
            [UIView beginAnimations:nil context:NULL];
            [UIView setAnimationDuration:0.25];
            self.view.center = CGPointMake(self.view.center.x, self.view.center.y+moveAmount);
            [UIView commitAnimations];
            isRaised = [NSNumber numberWithBool:NO];
        }
    }
    

    -EDIT-

    Looking at your code it appears that you’re subtracting from the y-coordinate of a frame to move frame down. The iOS coordinate system for CGRect is not the same as a normal coordinate system – the y-axis is flipped (this is relatively common for graphic systems). You’re going to want to do the opposite of what you’re doing.

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

Sidebar

Related Questions

I know this question has been asked quite a few times, however, I have
I know this kind of question has been asked a few times, but alot
I know this question has been asked here a few times before. But i
I know this question has been asked few times over SO but none of
I know this question has been asked a few other times but I have
I know this question has been asked a few times and in a few
I know this question has been asked a few times in various context, but
I know this question has been asked a couple of times. However, I can't
I know this question has been asked a couple of times before. I m
I know this question has been asked before however the answers I found where

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.