UICollectionViewController + UITextField autoscroll behavior

Hi all! I have a UICollectionViewController with cells that contain UITextField items. On iOS 14, switching firstResponder status between each text field programmatically caused the UICollectionView to auto-scroll the items into view.

On iOS 15 this behavior still occurs, but the animation is jittery. The scrollview jumps up and down rapidly while the animation occurs.

As a sanity check, I have no other code executing while this animation occurs. The contentInsets and contentOffset are only being affected by the firstResponder animation.

Any ideas why this might be happening?

Replies

Is it on device or on simulator ?

Is it exactly the same code you run on iOS 14 and iOS 15 ? Did you recompile with another version of Xcode ?

Do you test on the same model of iPhone ? Otherwise, that could be a constraints issue.

Could you show the code where you change firstResponder ?

  • Added my reply below.

Add a Comment

• This is on both an iPhone 12 and the simulator.

• This is the same code on both operating systems.

• I was previously using Xcode 12, but upgraded to the the Xcode 13 RC.

• I'm testing on the same model (both simulator and my personal dev device are iPhone 12s)

• The code where I change first responder is pasted below.

- (void)didPressNextButton {
    if (currentReponderIndex == self.textFields.count - 1) {
        NSNumber *tag = [self.textFields firstObject];
        UITextField *field = [self.view viewWithTag:tag.integerValue];
        [field becomeFirstResponder];

    } else {
        NSNumber *tag = [self.textFields objectAtIndex:currentReponderIndex + 1];
        UITextField *field = [self.view viewWithTag:tag.integerValue];
        [field becomeFirstResponder];
    }
}
  • When you compile project, do you get some warnings in Issue Navigator advising to adapt to new settings ?

  • Have you any specific code to perform the scroll, or is it automatically done with becomeFirstResponder ?

  • • I get no warnings in the issue navigator.

    • I have no code to perform the scroll; it's being done automatically with becomeFirstResponder and the contentInsetAdjustmentBehavior of the UICollectionView set to it's default value of .Automatic

Add a Comment

How much jitter do you get ? a few pixels or much more ? Is it when the cell is not completely visible or is it in all cases ?

I found this: could it help ? 

h t t p s : / / stackoverflow.com/questions/17435805/uicollectionview-activating-scrolling-to-and-assigning-first-responder-to-dis

  • • The jitter is pretty bad - I'd say at least 50 pixels up and down 4-5 times. • Thanks for the link! I took a look and an approach like that makes sense. I'm trying to avoid writing code to scroll to the focused cells since this behavior is implemented by Apple. I suspect that perhaps this is an iOS 15 bug.

  • You should submit a bug report, even if you are not totally sure it is an iOS bug.

Add a Comment

More questions than answers, sorry…

  • Did the problem occur with Xcode 12 ?
  • Could you show any code for Collection layout ?
  • Could be that iOS uses values to scroll before adapting to correct cell sizes ? That's just a guess.
  • Are all the cells of the same size ?
  • Have you a minimum example to try and reproduce ?

• I don't recall seeing this issue in the two months of previous testing on iOS 14 using Xcode 12.

• I'm using UICollectionViewCompositionalLayout with estimated heights that are about the same size as the rendered rows. I also have header and footer boundary elements.

• I thought it could be a layout pass as well, but when scrolling to the fields on my own, I don't see any jitter. It's only when the keyboard is visible and the system attempts to scroll the view.

• All the cells are the same size.

• I have prepared a minimum example and the issue is reproducible. dropbox.com/s/fpqy2tx7gpvdd69/CollectionViewTesting.zip?dl=0

I have submitted a bug report to Apple with this example project. ID is FB9640529.

  • Hi! Is there any news about this issue? I have the same problem. :(

Add a Comment