Stop table view from bouncing when presenting view controller - ios

I currently have a view controller that has a segmented control and a table view as subviews of its view. The following view controller is always displayed within a navigation controller (including its toolbar) and it’s subviews are laid out as follows:
Segmented control: Top, leading and trailing constraints are pinned to the superview with constant values of 0.
Table view: Bottom, leading and trailing constraints are pinned to the superview with constant values of 0.
The segmented controls bottom to the table views top have a constant value of 8.
The view is resized and works without any issues when displayed within a navigation controller. I can scroll both up and down and all cells are visible.
The current problem I have is when I have scrolled down to the last cell and I want to present another view controller using the presentViewController:animated:completion: method. The issue is the whole table view bounces up, hits the segmented control and scrolls up 1 cell to the second last cell automatically. This is a behaviour I do not want as I don’t want the user to have to scroll down to the last cell again. This happens even if only part of the last cell is visible. There is no bouncing when I present the view controller when the last cell is scrolled out of view.
So far I’ve tried turning off all bounces and it still doesn’t stop this behaviour.
Any ideas on what’s causing this and how I could stop it from happening? I’ve been stuck on this for the past 3 days.

Related

ScrollViews and Segmented controller

This is really odd, but I have a segmented controller and both of the views have a scroll view. So when you click on one half of the segmented controller that view has a scroll view, and the other half also has a scroll view. For some bizarre reason only one of the views will scroll. I need them both to scroll. Does this made sense?
First in the viewDidLoad I added a subview for both of them. Then I added an if else statement with .isHidden and that works beautifully.

Page view constraints bug

I have set up a page view controller in swift with a scroll view and a view inside the scroll view. I made constraints for both of them but when I run the project on swiping left or right between the pages the view in the scroll view first comes a little bit smaller and then when the swipe is completed it expands.
Here is the problem:

UIScrollView that has UITableViews as subviews won't scroll horizontally

I have a view controller that owns a UISegmentedControl, a UIScrollView, and several UITableViews. The segmented control and the scroll view are subviews of the view controller's root view. The table views are subviews of the scroll view. The scroll view takes up all the space below the segmented control and each table view is as large as the scroll view. Table views are placed horizontally aligned inside the scroll view.
The view controller should support scrolling to one of its table views either by selection in the segmented control (that works) or by swipe gesture (that does not work yet). I have checked that the scroll view's contentSize is appropriate and I have also tried turning the table view cells' userInteractionEnabled off. I have also checked that the table views do not exceed the size of the scroll view as discussed here. (Each table view is as large as the scroll view, albeit at a horizontal offset.) Still the scroll view can|t be swiped horizontally as I would expect.
Could it be that the table views themselves consume all (including horizontal) swipe gestures as part of their support for vertical scrolling? How can I ensure that the scroll view further up in the scroll hierarchy can (also) react to such swipe gestures?

Autolayout and embeded scroll views

I have a view that contains a scroll view and that scroll view has another 2 views in it: on top a standard view, and under that another view. This last view has a scroll view inside it. (a matroshka doll has nothing on this app) .
The problem is there is a button that causes the bottom view to resize and increase it's height, but the outer scroll view doesn't increase content size. So the bottom part of the bottom view (now resized to be bigger) is not visible.
Any suggestions on how to fix this mess ?

UITableView stops scrolling enough after I add/remove a view to the superview of table view

Here is the problem that I'm facing. I have UITableView inside main view. When user taps menu button, view is added to the view hierarchy of superview, and this view covers all screen, except the menu button. That is I call
[self.view insertSubview:self._menuView belowSubview:self._menuButton]
After user clicks the menu button again I call
[self._menuView removeFromSuperview]
However, after this, the UITableView stops scrolling, actually it scrolls, but just a little, couple of pixels, and then bounces back to the location on which it was before I inserted _menuView. I've monitored the menu hierarchy after inserting and removing the _menuView, it is actually removed, and also there is no view which covers the UITableVIew, so there is no chance that some other view steals touches from UITableView. What can be the problem? Any ideas?
EDIT 1: I've noticed besides not being able to scroll, another strange thing happens. When I show menuView, the tableView is scrolled to top, without animation. (the menuView is half opaque only, so I can see the tableView underneath it)
EDIT 2: I've monitored contentSize and contentOffset of tableView before and after inserting _menuView, the reason for not being able to scroll is that somehow contentSize is being changed.
TABLE VIEW BEFORE INSERTING MENU - contentSize:{Width=320, Height=10519} contentOffset:{X=0, Y=3980}
TABLE VIEW AFTER INSERTING MENU - contentSize:{Width=320, Height=44} contentOffset:{X=0, Y=0}
As You can see, the height is changed to 44 that's why I'm not able to scroll. And Also, as I've said in EDIT 1: tableView is scrolled to top - so as you can see contentOffset is also zeroed. Any ideas why content size changes automatically?
Thanks in advance.
i think there is problem with your tableview frame. right after removing subview, try to set frame of your tableview at its original frame.may this will solve your problem
Content in the UITableView organized automaically and designed only to show cells & header/footer elements. To proper working you should wrap your table into parentView and add your menu to that parentView rather than to the UITableView. You can also try to call reloadData method on table since it can restore the content size of the view.

Resources