简体   繁体   中英

IOS Navigation Bar in Master/Detail storyboard project is transparent on ipad but not on iphone

I'm working on an IOS app that was started with the default Master/Detail application storyboard.. I haven't changed the original layout except for to add an additional segue from the Detail View controller to a new UIViewcontroller which I'm representing with my own class. I'd like the navigation Bar to be transparent on the view controller that I added and I've found lots of examples on how to make that happen on the internet. The problem I'm having is that when tested on an ipad, the naviagation bar is transparent as expected, but on and Iphone no matter what I do the navigation bar stays the same.

I'm running the Xcode 7 beta and everything is coded in Swift.

In my viewDidLoad function for my View Controller I have the following lines of code:

self.navigationController!.navigationBar.translucent = true;
self.navigationController!.navigationBar.shadowImage = UIImage()
self.navigationController!.navigationBar.setBackgroundImage(UIImage(), forBarMetrics: UIBarMetrics.Default)
self.navigationController.navigationBar.backgroundColor = UIColor.ClearColor()

I've tried these lines in a bunch of different ways... here are some of the things I've tried

  1. running these lines in viewWillAppear instead.
  2. Running the same basic code on the object returned from UINavigationBar.appearance()
  3. getting the parent view controller and running the same settings on its navigationbar object.

None of these changes have had any effect on behavior. It appears that any IOS device where the Master View Controller displays first full-screen leave the navigation bar normal.. while any device that displays the details view or both views first shows the navigation bar transparent. I'm thinking I need to access the navigation bar in a different way in those scenarios.. but I'm out of ideas.

Thanks!

put

let navigationController = splitViewController!.viewControllers[splitViewController!.viewControllers.count-1] as! UINavigationController

on top of your code then change the self.navigationController! with navigationController and it will work.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM