Question

Have a legacy UISplitViewController iPad app that displays a modal view from the "right side" VC pane using presentViewController:animated:completion: with the modalPresentationStyle set to UIModalPresentationFormSheet. In viewDidAppear of the modal view's VC, we call becomeFirstResponder on a UITextField. In iOS6, this results in a centered modal view sliding up from the bottom which then focuses the KB. However, since iOS7, what occurs is after the view slides up from the bottom, it slides to the right by about (estimating) 200 points. Weird thing is, if you dismiss the keyboard, as soon as you do, the view slides back to it's centered position like it is on iOS6. From then on, while the modal view is up, KB focus causes it to stay centered and only slide up a little, which is normal iOS behavior for non full screen modal views. It's like once you dismiss the KB once it "corrects" itself from then on. I have experimented and found that:

  1. If you set animated to NO for the presentViewController call it works like iOS6.
  2. If you don't call becomeFirstResponder at all, it works like iOS6.
  3. If you call performSelector:xxxxafterDelay:0, passing becomeFirstResponder as the selector instead of calling becomeFirstResponder directly, it also works like iOS6.

Option 3 from above is currently my go forward workaround, but my question is: is this an iOS7 bug, or are we doing the wrong thing that was obviously ok in 6 but not in iOS7?

Only occurs post-iOS7. Only recreated once on simulator, but 100% of time on test device (iPad mini). From the searches I've done my current best guess (assuming our code isn't to blame post-iOS7) is there's a race condition type bug between the animations of the keyboard and the view sliding up from the bottom in the iOS UI layer that causes the view to shift right instead of up, like it normally does when a non full screen view is presented modally and the KB is popped. I got that theory after reading this similar SO question.

Was it helpful?

Solution

Had this problem. This is definitely a bug in iOS7.X. (You should open a bug report with Apple!). What happens is Apple has bug in its layout calculation and shifts the modally presented view.

We used

dispatch_async(dispatch_get_main_queue(), ^{ [view becomeFirstResponder]; }); 

to overcome the issue, which is similar to your #3. This delays the keyboard appearance until after the view's layout, overcoming the issue.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top