ScrollView and Navigation Bar ios9 - swift

I have a View Controller (named View2) embedded in a Navigation Controller.
In this view I have a ScrollView which covers all the view (including the navigation bar).
This View Controller is presented from another view with the call:
let view2 = self.storyboard?.instantiateViewControllerWithIdentifier("View2") as! View2
let modalStyle: UIModalTransitionStyle = UIModalTransitionStyle.CrossDissolve
let nav: UINavigationController = UINavigationController.init(rootViewController: view2)
nav.modalTransitionStyle = modalStyle
self.presentViewController(nav, animated: true, completion: nil)
In my View2, I adjust the navigation bar to be translucent:
navigationController?.navigationBar.setBackgroundImage(UIImage(), forBarMetrics: UIBarMetrics.Default)
navigationController?.navigationBar.shadowImage = UIImage()
navigationController?.navigationBar.translucent = true
But there is an issue, when View2 appears, the scrollview starts bellow the navigation bar. I have to tapp one time on the scrollview to see it auto-adjust at the top of the screen, over the navigation bar.
Any idea to fix it?
I want than the scrollview appears at the top of the screen, over the translucent navigation bar.
Thank you for your feedbacks,
Thomas

Did you try setting automaticallyAdjustsScrollViewInsets = false on your view controller?
Another option would be to uncheck the option "Under Top Bar" in the view controller's attributes inspector in "Extend Edges".
Hope this helps.

Related

How to display the tabs when click the back button from hided tab view controller

I created a tab bar controller and from one tab item I gave segue to the navigation view controller. And I create a some view controllers attached to navigation controller. So in one view controller I don't need a tabs so in that controller I wrote to hide the tab bar controller that is self.tabBarController?.tabBar.isHidden = true.
When I click the back button of navigation controller from hided tab view controller to previous controller, it doesn't show the tab bar items in previous controllers. But I needed tabs in all view controller except in one view controller. Why does it not show the tabs?
This is my story board :
You can try this in the VC that's before the one you hide the tab in
override func viewWillAppear(_ animated:Bool) {
super.viewWillAppear(animated)
self.tabBarController?.tabBar.isHidden = false
}
You can use hidesBottomBarWhenPushedin the view controller which you don't need tabs. Fits your situation.
let controller = ViewControllerTwo()
controller.hidesBottomBarWhenPushed = true
navigationController?.pushViewController(controller, animated: true)
A little more explanation:
self.tabBarController?.tabBar.isHidden = true globally changed the self.tabBarController's property hideTabBar across its children controllers stack.

white space on top of UITabBarController

i can't get rid of white space on top of my view. This only happens when I want to use navigation controller.
let viewController = ViewController()
let navController = UINavigationController(rootViewController: viewController)
self.present(navController, animated: true, completion: nil)
In your navController, add the following line in the viewWillAppear method.
navC.setNavigationBarHidden(true, animated: false)
A navigation controller adds a navigation bar by default on all its child view controllers. If you want the navigation bar to be hidden. We need to do it explicitly in each child view controller.
If you use Storyboard: Attribute Inspector > uncheck Adjust Scroll View Inset.
Or set programmatically:
self.automaticallyAdjustsScrollViewInsets = false

Make UIImage full screen overlaying Nav & Tabbar too

I have a picture that becomes full screen with black bars to preserve ratio. The problem I'm running into is that it doesn't go over the navbar and tabbar as well. I'm guessing the part of the code I need to change is in here
let imageView = sender.view as! UIImageView
let newImageView = UIImageView(image: imageView.image)
newImageView.frame = self.view.frame
newImageView.backgroundColor = .black
newImageView.contentMode = .scaleAspectFit
What can I set the newImageView frame to so it covers everything?
The problem is that the full screen image is behind the navigation bar and tab bar.
To set it to the full screen size, use UIScreen.main.bounds:
newImageView.frame = UIScreen.main.bounds
When presenting the full screen image, hide the navigation bar and tab bar:
self.navigationController?.isNavigationBarHidden = true
self.tabBarController?.tabBar.isHidden = true
When dismissing the full screen image, restore the navigation bar and tab bar:
self.navigationController?.isNavigationBarHidden = false
self.tabBarController?.tabBar.isHidden = false
Alternate solution
As #LeoDabus mentioned in the comments, you can solve this by presenting a new viewController which contains the imageView that covers the entire view. Present this viewController modally with:
self.present(newViewController, animated: false, completion: nil)
Note: Setting animated to false will allow the full screen image to appear without animation.

Why is button and title not showing up on navigation bar when I add them programmatically?

I tried to make a navigation bar programmatically with a button and title. For some reason, the navigation bar shows up, but the button and title does not. How do you fix this?
// Create the navigation bar
let navigationBar = UINavigationBar(frame: CGRectMake(0, 0, 500, 200))
//Create navigation bar's title
self.navigationController?.navigationBar.topItem?.title = "Edit"
//Create back button
let backBtn = UIButton(type: UIButtonType.Custom)
let backButtonItem = UIBarButtonItem(customView: backBtn)
self.navigationItem.leftBarButtonItem = backButtonItem
//Add navigation bar to view
self.view.addSubview(navigationBar)
For you question,since you didn't embeded viewcontroller to a navigationcontroller, so all your settings made no sense
self.navigationController? = nil &
self.navigationItem.leftBarButtonItem //there's no navigationcontroller made no sense
what you need to do is,embeded vc to navigationcontroller in proper time like
let navVC = UINavigationController(rootViewController: vc)
and then u could navigationController and set all stuffs

SWRevealViewController hide navigationBar for frontView

I added some code to auto display my MenuViewController (SWRevealViewController) but when I do that, my navigation bar of my front view disappear.
There is the code :
if (previousVC == "EditVC")
{
self.revealViewController().revealToggleAnimated(true)
self.revealViewController().setFrontViewController(self, animated: true)
// navigation bar disappear
}
I don't understand why my navigation bar is hidden. Can somebody help me?
It could be that you are setting the front view controller to a view that's not embedded in a Navigation Controller. My suggestion would be to segue normally and then setup your Sidebar menu again in viewDidLoad for the next view controller like so:
// Implement the menu bar functionality
if self.revealViewController() != nil {
menuButton.target = self.revealViewController()
menuButton.action = "revealToggle:"
self.view.addGestureRecognizer(self.revealViewController().panGestureRecognizer())
Also, you want to set the next view's navigation controller not its view controller. Since you're not doing a normal segue, you'll lose the navigation controller.
You just need to add one more Navigation Controller between your sw_front Navigation Controller and View Controller and hide the visibility of navigation bar of first navigation controller.