Everyone wants to move the UITableView when the keyboard pops up, but I'm looking for a way to disable the automatic animation to the cursor when the keyboard pops up. I'm experiencing an odd jerking / jolting / erratic scrolling behavior when the keyboard pops up and causes the UITableView to scroll to the cursor (to avoid blocking it).
Each of my UITableView cells has a UITextView in it. I don't commit any other animations when the keyboard pops up.
At this point, I would like to disable the animation completely and manually scroll to a desired CGPoint.
Thank you!
The automatic scrolling code resides in tableViewController, so auto-scrolling can't be disabled. Instead of subclassing from UITableViewController you can subclass from UIViewController and use a tableView inside it.
If you are willing to use UITableViewController itself, you can override viewWillAppear and don't call [super viewWillAppear].
Related
A custom UIViewController contains a UICollectionView. A UISearchBar should be placed at the very top of the collectionView and scroll with its content. If the user enters a search text into the content fo the collectionView should be updated while the searchBar retains its FirstResponder status.
Something pretty easy which seems to be astonishingly to realize.
I found several other topics dealing with kind of problem but they are all several years old and none of the proposed solution worked. I wonder what is the best solution in 2020 using Xcode 11 and iOS 13 to solve this problem.
What DID NOT work:
I have added the UISearchBar to the header of the first section. When reloading the complete contentView or its sections the searchBar looses firstResponder and the keyboard is dismissed.
I have added the UISearchBar as subview to the collectionView and used the collectionViews contentOffset to place the content below the search bar. Although the searchBar is part of the collectionVies dynamic view hierarch, the Problem is the same es before: When reloading the complete contentView or its sections the searchBar looses firstResponder and the keyboard is dismissed.
I have added an extras section to the collectionView which only shows its header (including the searchBar) bot not content. When reloading the other sections but keeping this "search section" the keyboard is dismissed.
It makes no difference if collectionView.performBatchUpdates is used or not.
Resetting the firstResponder Status after the collectionView or its sections does work. However in this case the keyboard is dismissed and re-appears immediately. Quick typing is not possible this way and the flashing of the keyboard is very annoying.
Is there any known clean approach to solve this?
Meanwhile I found a solution that works for me. Maybe it is also helpful for others:
I have added the searchbar as additional subview to the collectionView and used the contentInsets to move the actual content below it. Problem with this solution was, that when calling collectionView.reloadData() the searchbar lost its firstResponder status and the keyboard disappeared.
So, before calling collectionView.reloadData() I simply moved the searchbar to another view. Since it is not longer a subview of the collectionView it is not effected by the reload and does not loose firstResponder:
collectionView.superview.addSubview(searchBar)
collectionView.reloadData()
collectionView.addSubview(searchBar)
Not the prettiest solution but it works.
I have a UICollectionView with some UICollectionViewCells that contain UITextFields. When a UITextField is selected for editing, the keyboard shows and the UICollectionView moves up accordigly to make the active UITextField visible. I am relying on default behaviour with this and the UITextField is actually appropriately positioned when UIKeyboardDidShowNotification is launched. However, right after that, the UICollectionView will scroll automatically back to the top, and the UITextField will move out of view (behind keyboard).
What could be causing this and how could I debug this behaviour? Please note, that any custom code for UIKeyboardDidShowNotification like scrollRectToVisible or Apple's sample code will not help, as the scrolling off viewable areas happens at a later stage overriding that code. I am just unable to pinpoint the cause of this.
EDITED to add:
An animation to show how the view behaves with a hard keyboard (iPad Pro) when clicking Next to cycles fields. This works fine.
An animation to show how the view behaves with a soft keyboard when clicking Next to cycles fields. Here the keyboard avoiding does not work.
I'm developing an iPad app, that has a horizontal UICollectionView. Each of the cells has a UITextField. When the UITextField becomes first responder, the keyboard automatically comes up, and surprisingly all the cells move upwards.
I haven't implemented any logic for the cells to move upwards. Do you know why?
I haven't found any documentation regarding this, and I'm unable to fix this.
This behaviour is implemented by Apple. The standard UICollectionView takes care for you to scroll to the correct position if a keyboard appears. Why would you want to fix this?
I'm having problems with an animation inside the UICollectionview cell. When I touch my animation, it disappear. I have a refresh time of 8 seconds and when this time is reached, the animation back to normal. My labels inside the cells are having the same issue. It's weird this behavior because when I use static images, they don't disappear.
Arrived while looking for the answer to this. Faced similar issue. Image animation would stop when clicked on the collectionViewCell.
Not sure what the bug is, but one solution that worked for me, was to disable selection on the CollectionView.
In case, you do not need selection on the collection view, just set allowsSelection to NO for the collection view and the bug will go away.
I have UIScrollView with other UIView elements inside. My other UIView elements are mostly segmented controls. If I click on a UISegmentedControl and hold for a second and then try to scroll, then no scrolling happens. I can only scroll when my finger touches and swipes immediately. I checked other iOS applications such as mail. The behavior was that you touch and hold on a mail, then it's highlighted, but as soon as finger moves away, the scrolling happens and highlighting is undone. How can I implement this behavior?
The issue was the property of UIScrollView. The property canCancelContentTouches was set to NO. Because of that, touch events were handled by subviews of scroll view and swiping didn't cause scrolling.
You can follow one of these steps:
If you are using UISegmentedControl over you UIScrollView, instead of that, add the UISegmentedControl over your controller's view.
If you want to use UISegmentedControl over your scrollView, then you have to create a custom scrollView by creating a subclass of UIScrollView and use an image view instead of UISegmentedControl adding the labels which can act as the segments. This is because your UISegmentControl itself is a touch handler and it breaks the UIResponder chain. So, the scrolling might face issues during the touch events.
Please let me know if any of these works. Thanks :)