When a UITextField
, embedded in a UIScrollView
becomes first responder, by lets say the user typing in some character, the UIScrollView
scrolls to that Field automatically, is there any way to disable that?
相关问题
- CALayer - backgroundColor flipped?
- Core Data lightweight migration crashes after App
- How can I implement password recovery in an iPhone
- how do you prevent page scroll in textarea on mobi
- Custom UITableview cell accessibility not working
相关文章
- UITableView dragging distance with UIRefreshContro
- Could I create “Call” button in HTML 5 IPhone appl
- Unable to process app at this time due to a genera
- How do you detect key up / key down events from a
- “Storyboard.storyboard” could not be opened
- Open iOS 11 Files app via URL Scheme or some other
- Can keyboard of type UIKeyboardTypeNamePhonePad be
- Can not export audiofiles via “open in:” from Voic
Building on Luke's answer, to handle the issue that his solution completely disables auto-scroll, you can disable it selectively as follows:
This way, you can completely set it up in Interface Builder to disable the auto-scroll, but have full control at any time to re-enable it (though why you'd want to is beyond me).
An easier way to stop the scrollview scrolling when you select a textField is in your viewController::viewWillAppear() DO NOT call [super viewWillAppear];
You can then control the scroll as you wish.
I've tried @TaketoSano's answer, but seems not works.. My case is that I don't have a scrollview, just a view with several text fields.
And finally, I got a workaround. There're two default notification names for keyboard that I need:
UIKeyboardDidShowNotification
when the keyboard did show;UIKeyboardWillHideNotification
when the keyboard will hide.Here's the sample code I used:
Here, the
(CGRect){{272.f, 226.5f}, {480.f, 315.f}}
is view's default frame when keyboard is hidden. And(CGRect){{272.f, 55.f}, {480.f, 315.f}}
is view's frame when keyboard did show.And b.t.w., the view's frame changing will be applied animation automatically, this's really perfect!
As Taketo mentioned, when a
UITextField
is made first responder, its first parent view that is of typeUIScrollView
(if one exists) is scrolled to make thatUITextField
visible. The easiest hack is to simply wrap each UITextField in aUIScrollView
(or ideally, wrap all of them in a single dummyUIScrollView
). This is very similar to Taketo's solution, but it should give you slightly better performance, and it will keep your code (or your interface in Interface Builder) much cleaner in my opinion.I don't know of any property of
UIScrollView
that would allow that. It would be poor user experience to be able to disable that, IMHO.That said, it may be possible to subclass
UIScrollView
and override some of its methods to check that theUITextfield
is not a first responder before scrolling.