When a UITextField
is added to a UIScrollview
the scroll view automatically adjusts its contentOffset
so that the view will not be obscured by the keyboard.
I have a custom UIControl
which also presents a keyboard when it becomes the first responder by assigning its inputView
property. The same scrolling behavior does not work. Is there a way to configure a UIControl
such that a scroll view will keep it visible when the keyboard is presented?
My guess is that it could be possible by overriding a property defined in one of the protocols UITextField
and other classes which this behavior conform to. But these can be a bit of a maze. Also note, the issue here has nothing to do with the scroll view's contentInset
property. The scroll view can scroll to show the custom control, it just doesn't do it automatically when the control becomes the first responder.
It looks like this is handled by an internal private method that Apple utilizes
[UIFieldEditor scrollSelectionToVisible]
as noted on this blog: http://sugarrushva.my03.com/712423-disable-uiscrollview-scrolling-when-uitextfield-becomes-first-responder.htmlIt appears to do this by stepping back up through the view hierarchy and if it finds a parent
UIScrollView
, it scrolls the view to bring theUITextField
into visible view. You'll need to implement the scrolling manually on your custom control when it becomes first responder, or handle it by introspecting the parent views.