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
I have a collection view with a text field at the very top, mimicking the
UITableView.tableHeaderView
. This text field is located in the negative content offset space so that it doesn't interfere with the rest of the collection view. I basically am detecting whether or not the user is performing the scrolling in the scroll view and whether or not the text field is first responder and if the scroll view is being scrolled beyond the top of the scroll view's content inset. This exact code won't necessarily help anyone but they could manipulate it to fit their case.This is the way I do it:
It is very simple, you get to return your own contentOffset for any scrollRectToVisible.
This way you are not harming the normal behaviour and flow of things - just providing the same functionality in the same channel, with your own improvements.
I've been struggling with the same problem, and at last I've found a solution.
I've investigated how the auto-scroll is done by tracking the call-trace, and found that an internal
[UIFieldEditor scrollSelectionToVisible]
is called when a letter is typed into theUITextField
. This method seems to act on theUIScrollView
of the nearest ancestor of theUITextField
.So, on
textFieldDidBeginEditing
, by wrapping theUITextField
with a newUIScrollView
with the same size of it (that is, inserting the view in between theUITextField
and it's superview), this will block the auto-scroll. Finally remove this wrapper ontextFieldDidEndEditing
.The code goes like:
hope this helps!
I had the same issue with disabling auto-scrolling of a
UITextView
being a cell ofUITableView
. I was able to resolve it using the following approach:Defining
scrollViewWillBeginDragging
is used for restoring the default scrolling behaviour, when the user himself initiates scrolling.It looks like UIScrollview which contains UITextfield, auto adjusts its content offset; when textfield is going to become first responder. This can be solved by adding textfield in scrollview of same size first, and then adding in to main scroll view. instead of directly adding in to main scrollview
Building on Moshe's answer...
Subclass UIScrollView and override the following method:
Leave it empty. Job done!