UISearchController as UITableViewHeader - ios

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
}

Related

How to hide tableView header?

I have my tableview with search bar added in it.
actionsTableView.tableHeaderView = searchController.searchBar
I want my tableView appear with hidden header, which will appear when I scroll up.
As a reference you can have a look on Telegram/WeChat/WhatsApp messengers, they have implemented this feature.
Try this inside of viewDidLoad,
[self.myTableView setContentOffset:CGPointMake(0.0f, 40) animated:NO];
Note: Add your UISearchBar inside of UITableView
Add your searchBar and tableView in a view(say mainView).
Add mainView to the view controller and assign its top(topConstant) to -40(considering its the height of search bar) , and assign the leading,trailing and bottom to view controller.
Now assign scrollview delegate to your class and check if tableview is scrolled on top by checking its velocity.
now add Animation and set topConstant to 0.

View not reaching the bottom of the device screen using Autoresize Subviews

I have a view controller that has a button at the top center, and a view underneath which will have the collectionview inside. I want this collectionview to scroll separately to the top view (so it scrolls underneath that top section).
This works fine but the view with the collectionview doesn't reach the bottom. You can see in the screenshot I gave the superview a red background - the collectionview doesn't reach to the bottom of the view. All the constraints are fine.
It works if I uncheck "Autoresize subviews" in the Interface Builder for the UIView inside the View Controller but this then makes all the cells and any navigation bars I add inside that view 1000px wide. Why is my view being shortened - and how can I get the best of both these scenarios? A View that hits the bottom of the screen and all the cells/navigation bars the width of the view?
Constraints for the view:
Constraints for the collectionview:
I did have a tab bar too, and the gap is the exact height of my tab bar.
Anyway I fixed this by putting:
self.extendedLayoutIncludesOpaqueBars = YES;
self.edgesForExtendedLayout = UIRectEdgeBottom;
in viewDidLoad method.

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).

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?

How to add a search bar at the bottom of a table view in Xcode?

I am developing an iOS application, and I want to add a search button that initiates a search of a table view. When searching, the search bar should not be scrolled with the table cells.
To make a search bar (or any view really) "stick" to the top or bottom of a UITableView there are two approaches:
Adjust the frame of the table to be the view height minus the height of your bar, and then set the bar's frame to {0, 0, CGRectGetWidth(self.tableView.frame), CGRectGetHeight(self.tableView.frame)}, which would position it statically at the bottom of the view. If you are using a stock UITableViewController, you'll need to do some additional work because self.view and self.tableView both point to the same object. You'll need to set a new UIView to self.view which will then be the container for the table view and your search bar view.
Add the bar as a subview of table, then implement UIScrollViewDelegate in your controller and use scrollViewDidScroll: (which fires whenever the user scrolls the view) to update the bar's position. The new position would be something like:
CGRect adjustedFrame = self.searchBarView.frame;
adjustedFrame.origin.y = self.tableView.contentOffset.y + CGRectGetHeight(self.tableView.frame) - CGRectGetHeight(self.searchBarView.frame);
self.searchBarView.frame = adjustedFrame;

Resources