Managing UITableView contentInsets - ios

I have controller, call it ActionBarViewController (it inherits UIViewController). It has view, call it ActionBarView. That view has 2 subviews - contentView and actionBar. contentView frame equals to ActionBarView frame. actionBar frame is small frame at bottom part of ActionBarView frame.
I have one more controller - ListViewController (it inherits UITableViewController). I use it as childViewController with ActionBarViewController as parent. ListViewController's view (tableView) set as contentView of ActionBarView.
As result, i have UITableViewController that is childViewController. ParentViewController view has additional subview - action bar.
For correct table view scrolling i add/remove additional contentInsets of tableView on actionBar show/hide. But ListViewController add/remove contentInsets on his own when keyboard appeared/disappeared.
Finally, when keyboard shown tableView has complex bottom insets, keyboard insets and actionBar insets.
Questions:
Any body knows correct way to resolve this issue?
In which point UITableViewController change tableView insets? How to override it?
P.S.: All views and controllers creating programmatically.

Related

Disable Safe Area insets for UIViewController inside UIScrollView. (TikTok-like vertical feed)

I want to build a TikTok-like vertical CollectionView in which each cell is an UIViewController.
I'm having issues with managing safe area insets in those content View Controllers.
Since they are inside the scroll view, I don't want their safe-area insets to update as their change their position.
I've tried "disabling" safe area insets on some view by overriding safeAreaInsets property and returning zero insets.
// In my subclass of UICollectionViewCell
// MyCell.swift
override var safeAreaInsets: UIEdgeInsets {
.zero
}
However, it doesn't always work - especially when I add another UIViewController's view inside that view.
Here's the video that demonstrates the issue: Video link
What is the best way to control safe area insets in scroll views?
Is there any way to force UIView/UIViewController to have specific safe area insets that doesn't change as the view is changing its position (and going beneath the iPhones notch)?

UISearchController as UITableViewHeader

I am having a view controller with a UITableView and a Custom View.The storyboard configuration is Custom View is alligned with top, leading and trailing margin of my view controller's main view.Custom View is having a constant height. UITableView's top is alligned with bottom of the Custom View. UITableView's leading, trailing and bottom is alligned with leading, trailing and bottom of main view. I am adding a UISearchController's search bar as UITableView header. This view controller is pushed on UINavigationController Stack. Now when user clicks on search bar navigation bar hides to make way for searchbar.But as custom view is above the UITableView it accomodates the position where UISearchBar should have been. I want to move Custom View out also and take the UISearchBar position which would have been in normal scenario without Custom View above. Help will be appreciated.
Set the the IBOutlet for the Custom View's Height constraint and when user clicks on search bar then set e.g "customview.heightConstraint.constant = 0"
in search bar delegate method
func searchBarTextDidBeginEditing(_ searchBar: UISearchBar){
customview.heightConstraint.constant = 0
}

Stretch UIView in a ContentView of a ScrollView

I have the following problem:
I have a Scrollview with Autolayout top,left,bottom,right is set on 0, in this ScrollView is a ContentView also set everything on 0. The ContentView contains a ImageView a Segmented Control and a UIView which is connected to 2 different UIViewController.
The UIView is set top 0 to the Segmented Control and to bottom 0 to the contentView.
My Problem is that the UIView in the ContentView is not streets to the bottom of the ContentView. How can i solved this Problem?
Picture 1:
Storyboard UIViewController with ScrollView
Picture 2:
View on an iPhone 6 Plus
Here there are the size inspector constraints pictures:
ScrollView
MainView of Controller
ContentView in ScrollView
UIView in ContentView
Seems like the problem is in scroll view bottom content inset. By default scroll view have automaticallyAdjustsScrollViewInsets property enabled, and if you insert scroll view as nearest view to tab bar (as I can see at screenshot), bottom inset will set as nonzero (this used for show content under transparent tab bar while scrolling). But for use this behavior properly, you should connect scroll view bottom to view (root view) bottom, not to bottomLayoutGuide. Second option - disable automaticallyAdjustsScrollViewInsets property and handle contentInset and scrollIndicatorInsets properties of scroll view manually (set them to UIEdgeInsetsZero if you don't want change your constraints).

iOS Storyboard: how do you edit a content view larger than screen in a UIScrollView

I have a view that is larger than screen, I need to put it in a UIScrollView.
So I first add an UIViewController to story board, then, I add a UIScrollView to the root view of my view controller, then when I add subviews of UIScrollView, but I can't add them outside the scrollview area I can see, how to solve this problem?
Change the simulated size of the view controller to Freeform and then you can set the size to whatever you want. After editing, you may want to set it back.
Edit 1:
1) put your subview into scrollview's visible area
2) change frame of the new subview as you wish
3) change contentSize property of scrollview with runtime attributes
Edit 2:
u can create a new view with xib, which contains all your subviews, and then add this view on scrollview OR u can use storyboard's Container View like this:
p.s.: don't forget about contentSize (point 3 in my first edit), but if you are using auto-layout, you need to set it programmatically like this:
- (void)viewDidLayoutSubviews {
[super viewDidLayoutSubviews];
_scrollView.contentSize = CGSizeMake(320, 250);
}
put a scroll view in the view controller ,and put a view inside the scroll view named containerView.
design the big content in another view controller (named bigContentView)
in code ,view load event ,
a. get the bigContentView by storyboard Id. ( get the controller and use controller.view)
b. create the outlet to the containerView.
c. update the containerView's frame according your requirement.(update the width and height)
d. bigContentView.autoresizingMask = UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth;
e. containerView addSubView:bigContentView.

unable to get embedded scroll view to scroll

I'm using storyboard to create a details view. I have a UITabViewController, which then goes to a UITableViewController, then to my MessageDetailsViewController, which is a subclass of UIViewController. My controller's main view also has a UIScrollView subview, which contains all of my elements as subviews.
In storyboard, my layout has the navigation bar at the top, and the tab bar at the bottom.
I resized the UIScrollView to fill the full parent view, going behind the tab bar and navigation bar.
I set up some static subviews in the scroll view, then I add a bunch of extra labels to the scroll view dynamically in a for loop. In the simulator, the labels are showing up where I'd expect them to, but I cannot get the view to scroll. I'm setting the scroll view's content size with:
self.scrollView.contentSize = CGSizeMake(self.scrollView.frame.size.width, y);
Where y is the frame.origin.y + frame.size.height + VerticalBuffer of the final item (it shows up as 1200+ in my log message, so it's getting calculated properly).
What am I missing to make it scroll properly?

Resources