I'm using SCPageViewController in my app:
class RootPageViewController: UIViewController {
var pageViewController : SCPageViewController = SCPageViewController()
var viewControllers = [UIViewController]()
......
in viewDidLoad I'm configuring it:
self.pageViewController.setLayouter(SCPageLayouter(), animated: false, completion: nil)
self.pageViewController.easingFunction = SCEasingFunction(type: SCEasingFunctionType.linear)
self.pageViewController.dataSource = self;
self.pageViewController.delegate = self;
self.addChildViewController(self.pageViewController)
self.pageViewController.view.frame = self.view.bounds
self.view.addSubview(self.pageViewController.view)
self.pageViewController.didMove(toParentViewController: self)
I'm setting size of content view controllers in SCPageViewController data source method to be size of RootPageViewController. When app launches, I have my "status bar" that is just plain UIView with background color behind system status bar. But when I'm scrolling to next/previous page, it is offset by few pixels. How I can unify that? Why I'm getting this small offset on top?
I'm using Storyboards to model view controllers:
This is how it looks after app launches (as expected):
And when I scroll to next page:
This white area shouldn't be there... Everything is fine after I rotate device.
You could change the originY for the view to move it up a bit:
yourView.frame.origin.y = -5
BUT you should take a look at your constraints and see what happens to them when you change view and see if you could solve it that way instead. Because the solution provided above will move up the view, so you will have - 5 pixels at the bottom.
I am trying to display a simple search screen for my iphone app using a UISearchController.
I used a UITableViewController and a UISearchController that I embedded inside a UINavigationController
This get me the following screen (state 1)
When user click on the search field I get the screen below (state 2):
The search bar display nicely at the top of the screen below the status bar.
What I want to do is to get state 2 straight away without going to state 1
I tried to add this code
presentViewController(searchController, animated: true, completion: nil)
but it either does not show the searchbar if animated is false or display it as I want but after an unnecessary transition that temporaryly shows the navigation bar
Ok I just found how to do it reading this answer UISearchController in a UIViewController
I just need to add the searchbar like this to get the desired effect
searchController.hidesNavigationBarDuringPresentation = false
// tableView.tableHeaderView = searchController.searchBar
navigationItem.titleView = searchController.searchBar
I recently started to rewrite my iOS app to use the new UISearchController and a universal storyboard.
My app is available for both devices (iPhone and iPad) so the change to the universal storyboard using the UISplitViewController was a big advantage.
But sadly the UISearchController isn't working as expected. I added the UISearchController with the following lines:
self.searchController = UISearchController(searchResultsController: nil)
self.searchController.searchBar.sizeToFit()
self.searchController.dimsBackgroundDuringPresentation = false
self.myTableView.tableHeaderView = self.searchController.searchBar
self.searchController.searchResultsUpdater = self
self.definesPresentationContext = true
My controller chain is like that:
UISplitViewController
UITabbarController (Master)
UINavigationController
UITableViewController
UINavigationController (Detail)
UINavigationController
UIViewController
The problem is that in the iPad app the UISearchBar is covered by the UINavigationBar. But if I switch the tabs and go back to the view. The UISearchBar is visible. So somehow after a tabbar switch it redraws the view correctly. In the iPhone Version it works automatically correct.
iPad App
After the first launch the UISearchBar is covered by the UINavigationBar
After switching the tabs the UISearchBar is displayed correctly
iPhone App
The iPhone app is working correctly without changing the tabs..
What I tried:
Using different settings of extendingEdges
Add the SearchController in the viewWillAppear method because I thought I can trick it by adding the search control later on
I assume you setup search controller self.searchController.searchBar.sizeToFit() in viewDidload. Beside that, you need to add this method (Objective-C code):
- (void)viewDidLayoutSubviews {
// you could check
// if (IS_IPAD || (IS_IPHONE_6PLUS && UIDeviceOrientationIsLandscape([UIDevice currentDevice].orientation)))
[self.searchController.searchBar sizeToFit];
}
In case it does not work, you could add these codes into your viewDidlLoad or viewDidLayoutSubviews:
self.edgesForExtendedLayout = UIRectEdgeNone;
self.yourTableViewController.edgesForExtendedLayout = UIRectEdgeNone;
If you wants to dock your search, please refer my answer here
I have a minor trouble hiding the navigationBar for my UINavigationController
I have added:
self.navigation!.navigationBar.hidden = true
This, unfortunately leaves some kind of background (white) left behind the white status bar that pushes the content (green) downwards, and an unwanted scroll behaviour where I can drag the content up and down to show/hide the white background. What I need is for the statusbar to take up no vertical space what so ever and lay on top of the content (green)
How do I achieve this?
Answers in swift as well obj-c are very welcome
EDIT:
I have tried various versions of the following, the problem remains -.-
override func loadView() {
self.view = UIView(frame:UIScreen.mainScreen().bounds)
self.view.backgroundColor = UIColor.whiteColor()
self.navigation = UINavigationController(rootViewController: self.guideViewController!)
self.navigation!.navigationBarHidden = true
self.navigation!.setNavigationBarHidden(true, animated: true)
self.view.addSubview(self.navigation!.view)
}
override func viewDidLoad() {
self.automaticallyAdjustsScrollViewInsets = false
self.navigation!.automaticallyAdjustsScrollViewInsets = false
}
EDIT 2:
printing:
UIApplication.sharedApplication().statusBarFrame.size.height
after viewDidLoad returns 20
Updated :
Just add this in you ViewDidLoad method
self.automaticallyAdjustsScrollViewInsets = NO;
You can use hide navigation bar like
[self.navigationController setNavigationBarHidden:YES];
Hide status bar
// Hide status bar iOS 7 or later
- (BOOL)prefersStatusBarHidden
{
return YES;
}
Look at this site: https://developer.xamarin.com/recipes/ios/content_controls/navigation_controller/make_the_nav_bar_disappear/
This site says that "The behavior is slightly different depending on whether the Nav Bar is opaque or translucent"
I hope it is helpful.
[self.navigationController setNavigationBarHidden:YES animated:animated];
I know the question has already been answered but I was having the same issue when hiding a navigation bar then using a UIScrollView in the view.
I fixed it programmatically using:
self.edgesForExtendedLayout = UIRectEdgeNone;
Or in interface builder by deselecting all of these:
I am building an iOS 7-only app. I am trying to set a UISearchDisplayController into the navigation bar.
I have it set up like this: In the storyboard, I added a "Search Bar and Search Display Controller" to my view controller's view, and set it at (0,0) relative to the top layout guide. I set constraints to pin to left, top and right. (I played with the constraints, i removed them completely, it doesn't matter) On top of that I have my Table view. When I added the search bar to the view in the storyboard, it automatically setup outlets for searchDisplayController and searchBar delegate. In code I have self.searchDisplayController.displaysSearchBarInNavigationBar = YES; I have two problems:
1) Without any buttons showing for the search bar (Interface builder -> select search bar -> Options: none selected) the search bar is in the middle of the screen:
If I click on the navigation bar, it starts editing the search bar:
notice also that the dark overlay appears to be offset from the navigation bar. It seems to me that the space is the same height as the navigation bar. Like it has been shifted down by that much. Also, when it displays the search results, the top of the content view is shifted down by the same amount (more pictures follow), which brings me to the second problem.
2) I messed around with it for a while and decided to check the option to have it show the cancel button. Now I have the search bar embedded in the nav bar correctly, but the overlay is still shifted down:
Again, when the search results table view appears, it is shifted down by the same amount (notice the scroll bar on the right side):
Even more bizarrely, I set a border on the search display controller's tableview layer, and it appears correct:
I have never used the UISearchDisplayController before and I unfamiliar with how to set it up, but functionally it works fine. I have read some other similar posts but the only advice is to hack it up by adjusting frames and setting manual offsets. I'd prefer to know what is causing this, is it a bug? Something I'm doing wrong? If it's a bug I can wait for a fix. It seems like such a basic thing that a thousand people must have done without any problem so I feel like I'm not setting it up correctly somehow. Thanks for you input.
I remember running into the same exact problem that you are observing.There could be a couple of solutions you can try.
If you are using storyboards
You should click on the view controller or TableView Controller which you have set up for your tableview and go to its attribute inspector and look under ViewController section and set the Extend Edges section to be under Top Bars.
If you are not using storyboards you can manually set the settings using the viewcontrollers edgesForExtendedLayout property and that should do the trick. I was using storyboards.
In my case, using storyboards, I had to check both Under Top Bars and Under Opaque Bars and leave Under Bottom Bars unchecked.
In my case, I actually had to uncheck all the Extended Edges boxes (essentially the same as programmatically setting Extended Edges to UIRectEdgeNone I believe) in my Storyboard in order to stop my search bar from offsetting itself. Thank you guys!
definesPresentationContext = true
override func viewDidLoad() {
super.viewDidLoad()
searchController = UISearchController(searchResultsController: nil)
searchController.searchResultsUpdater = self
searchController.hidesNavigationBarDuringPresentation = false
searchController.dimsBackgroundDuringPresentation = true
searchController.searchBar.searchBarStyle = UISearchBarStyle.Prominent
self.tableView.tableHeaderView = searchController.searchBar
definesPresentationContext = true
or see UISearchBar presented by UISearchController in table header view animates too far when active
My problem was just Adjust scroll view inserts. After change to false I didn't have problem
I had a same problem. And I solve this issue with adding view object under the tableview.
Add new ViewController on the Storyboard
Drag TableView to the new VC
Drag Table Cell to the TableView
Make a Connection for TableView DataSource, TableView Delegate to the new VC
I had very similar behavior happening. For me, the solution was to uncheck Extend Edges Under Top Bar in the storyboard settings for the parent view controller (I've turned off transparent navbars, not sure if that effects anything). If you're not using storyboard, you have to set [UIViewController edgesForExtendedLayout].
From the Apple docs:
This property is only applied to view controllers that are embedded in containers, such as UINavigationController or UITabBarController. View controllers set as the root view controller do not react to this property. Default value is UIRectEdgeAll.
Unfortunately none of the above solutions worked for me, I'm using a UITableViewController.
This link helped:
http://petersteinberger.com/blog/2013/fixing-uisearchdisplaycontroller-on-ios-7/
I put the code below for convenience:
static UIView *PSPDFViewWithSuffix(UIView *view, NSString *classNameSuffix) {
if (!view || classNameSuffix.length == 0) return nil;
UIView *theView = nil;
for (__unsafe_unretained UIView *subview in view.subviews) {
if ([NSStringFromClass(subview.class) hasSuffix:classNameSuffix]) {
return subview;
}else {
if ((theView = PSPDFViewWithSuffix(subview, classNameSuffix))) break;
}
}
return theView;
}
- (void)correctSearchDisplayFrames {
// Update search bar frame.
CGRect superviewFrame = self.searchDisplayController.searchBar.superview.frame;
superviewFrame.origin.y = 0.f;
self.searchDisplayController.searchBar.superview.frame = superviewFrame;
// Strech dimming view.
UIView *dimmingView = PSPDFViewWithSuffix(self.view, #"DimmingView");
if (dimmingView) {
CGRect dimmingFrame = dimmingView.superview.frame;
dimmingFrame.origin.y = self.searchDisplayController.searchBar.frame.size.height;
dimmingFrame.size.height = self.view.frame.size.height - dimmingFrame.origin.y;
dimmingView.superview.frame = dimmingFrame;
}
}
- (void)setAllViewsExceptSearchHidden:(BOOL)hidden animated:(BOOL)animated {
[UIView animateWithDuration:animated ? 0.25f : 0.f animations:^{
for (UIView *view in self.tableView.subviews) {
if (view != self.searchDisplayController.searchResultsTableView &&
view != self.searchDisplayController.searchBar) {
view.alpha = hidden ? 0.f : 1.f;
}
}
}];
}
// This fixes UISearchBarController on iOS 7. rdar://14800556
- (void)correctFramesForSearchDisplayControllerBeginSearch:(BOOL)beginSearch {
if (PSPDFIsUIKitFlatMode()) {
[self.navigationController setNavigationBarHidden:beginSearch animated:YES];
dispatch_async(dispatch_get_main_queue(), ^{
[self correctSearchDisplayFrames];
});
[self setAllViewsExceptSearchHidden:beginSearch animated:YES];
[UIView animateWithDuration:0.25f animations:^{
self.searchDisplayController.searchResultsTableView.alpha = beginSearch ? 1.f : 0.f;
}];
}
}
- (void)searchDisplayControllerWillBeginSearch:(UISearchDisplayController *)controller {
[self correctFramesForSearchDisplayControllerBeginSearch:YES];
}
- (void)searchDisplayControllerDidBeginSearch:(UISearchDisplayController *)controller {
[self correctSearchDisplayFrames];
}
- (void)searchDisplayControllerWillEndSearch:(UISearchDisplayController *)controller {
[self correctFramesForSearchDisplayControllerBeginSearch:NO];
}
- (void)searchDisplayController:(UISearchDisplayController *)controller didShowSearchResultsTableView:(UITableView *)tableView {
// HACK: iOS 7 requires a cruel workaround to show the search table view.
if (PSPDFIsUIKitFlatMode()) {
controller.searchResultsTableView.contentInset = UIEdgeInsetsMake(self.searchDisplayController.searchBar.frame.size.height, 0.f, 0.f, 0.f);
}
}
Go to storyboard.
Click on the view controller.
Go to attribute inspector under the ViewController section.
Set the Extend Edges section to be Under Top Bars and Under Opaque Bars.
Make sure to un-check Under Bottom Bars.