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

  • Home
  • SEARCH
  • 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 6687309
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T05:16:24+00:00 2026-05-26T05:16:24+00:00

I have a UITextField inside a UIScrollView (a few levels deep). I am watching

  • 0

I have a UITextField inside a UIScrollView (a few levels deep). I am watching UIKeyboardDidShowNotification, and also calling the same code when I manually change the first responder (I might change to a different text field without momentarily hiding the keyboard). In that code I use scrollRectToVisible:animated: to make sure the UITextField is visible.

I was having a huge headache debugging why that was acting funny, but I realized now that UIScrollView automatically ensures that the first responder is within its bounds. I am changing the frame of the UIScrollView so that none of it is hidden behind the keyboard.

However, my code can be slightly smarter than their code, because I want to show not only the UITextField, but some nearby related views as well. I try to show those views if they will fit; if not whatever, I try to show as much of them as I can but at least ensure that the UITextField is visible. So I want to keep my custom code.

The automatic behavior interferes with my code. What I see is the scroll view gently scroll up so that the bottom edge of my content is visible, then it snaps down to where my code told it to position.

Is there anyway to stop the UIScrollView from doing its default capability of scrolling the first responder into view?

More Info

On reviewing the documentation I read that they advise to change the scroll view’s contentInset instead of frame. I changed that and eliminated some unpredictable behavior, but it didn’t fix this particular problem.

I don’t think posting all the code would necessarily be that useful. But here is the critical call and the values of important properties at that time. I will just write 4-tuples for CGRects; I mean (x, y, width, height).

[scrollView scrollRectToVisible:(116.2, 71.2, 60, 243) animated:YES];

scrollView.bounds == (0, 12, 320, 361)

scrollView.contentInset == UIEdgeInsetsMake(0, 0, 118, 0)

textField.frame == (112.2, 222.6, 24, 24)

converted to coordinates of the immediate subview of scrollView == (134.2, 244.6, 24, 24)

converted to coordinates of scrollView == (134.2, 244.6, 24, 24)

So the scroll view bottom edge is really at y == 243 because of the inset.

The requested rectangle extends to y == 314.2.

The text field extends to y == 268.6.

Both are out of bounds. scrollRectToVisible is trying to fix one of those problems. The standard UIScrollView / UITextField behavior is trying to fix the other. They don’t come up with quite the same solution.

  • 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-26T05:16:25+00:00Added an answer on May 26, 2026 at 5:16 am

    I didn’t test this particular situation, but I’ve managed to prevent a scrollview from bouncing at the top and bottom by subclassing the scrollview and overriding setContentOffset: and setContentOffset:animated:. The scrollview calls this at every scroll movement, so I’m fairly certain they will be called when scrolling to the textfield.

    You can use the delegate method textFieldDidBeginEditing: to determine when the scroll is allowed.

    In code:

    - (void)textFieldDidBeginEditing:(UITextField *)textField
    {
        self.blockingTextViewScroll = YES;
    }
    
    -(void)setContentOffset:(CGPoint)contentOffset
    {
        if(self.blockingTextViewScroll)
        {
            self.blockingTextViewScroll = NO;
        }
        else
        {
            [super setContentOffset:contentOffset];
        }
    }
    
    
    -(void)setContentOffset:(CGPoint)contentOffset animated:(BOOL)animated
    {
        if(self.blockingTextViewScroll)
        {
            self.blockingTextViewScroll = NO;
        }
        else
        {
            [super setContentOffset:contentOffset animated:animated];
        }
    }
    

    If your current scroll behaviour works with a setContentOffset: override, just place it inside the else blocks (or preferably, in a method you call from the else blocks).

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

Sidebar

Related Questions

In my application I have a UITextField inside a UITableViewCell . If I click
Well, I have a UITextField. Inside it is a property UITextField.text. Is it ok
I have a UITextField inside a UITableViewCell. It will not activate on the iPad
I have a strange problem with UITableView and UITextField inside the cell (as subview).
How can one draw a progressbar inside a UITextField ? I have tested two
I have UITextField inside a UITableView. I've set the delegate of the text view
I have a UITextField inside of a UITableView cell. When I rotate the device,
I have view controller, and inside I have IBOutlet UITextField *title , which is
I have a UIDatePickerView inside UIActionSheet as a input to the UITextField. When focusing
I have a UITextField inside of my UITableViewCell on my iPad app. If I

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.