UINavigationBar.appearance (). Translucent creates a large empty space

UPDATE 2 : I still hope to get some help in resolving this problem, so I will now clarify my question a bit, that I narrowed it down better.

My hierarchy is UIViewControlleras follows:

enter image description here

The filter view is displayed if the user touches the filter icon and selects the type of lift. The image on the left is what it looks like without the filter selected, and the correct image looks as if the filter is selected. The navigation area (highlighted in green) is what I'm trying to create.

enter image description here

This is what I just can't understand. If I add these two things:

UINavigationBar.appearance().translucent = false
UINavigationBar.appearance().barTintColor = UIColor(hexString: "232B35")

then a space appears between the navigation area and the filter view:

enter image description here

true, , barTintColor .

, UINavigationBar UIViewController. UINavigationItem, .

: , UINavigationBar.appearance().translucent = false ( , , )?

. !

, : . UIViewController ThemeManager struct , , :

static func applyTheme(theme: Theme) {

    // set the background color
    sharedApplication.delegate?.window??.backgroundColor = UIColor(hexString: "232B35")

    UINavigationBar.appearance().translucent = false // these are the offenders
    UINavigationBar.appearance().barTintColor = UIColor(hexString: "232B35")


    // first, set backgroundimage to nothing
    UINavigationBar.appearance().setBackgroundImage(
      UIImage(),
      forBarPosition: .Any,
      barMetrics: .Default)

    // and also set shadowimage to nothing
    UINavigationBar.appearance().shadowImage = UIImage()

    UIStatusBarStyle.LightContent
    UILabel.appearance().textColor = UIColor(hexString: "768DAA")
    }
  }

ViewController , , - , :

enter image description here

, :

enter image description here

, UINavigationBar.appearance().translucent UINavigationBar.appearance().barTintColor, . UINavigationBar . , , , , , :

enter image description here

VC : VC, , , UINavigationBar , VC . UINavigationItem . : VC UITableView, UITableViewController.

, , ?

№ 1 UIViewController :

enter image description here

, - UIView @IBOutlet, /img/1e07f4fddbb23e8a010d3ede6928160e.png > , (a UIView), UITableView. , , , .

, , viewDidLoad UIViewController:

LiftLogViewController: UIViewController, UITableViewDataSource, UITableViewDelegate, NSFetchedResultsControllerDelegate {

//MARK: IB outlets

  @IBOutlet var tableView: UITableView!
  @IBOutlet weak var navItem: UINavigationItem!
  @IBOutlet weak var filterViewHeightConstraint: NSLayoutConstraint!
  @IBOutlet weak var clearFilterButton: UIImageView!
  @IBOutlet weak var selectedFilter: UILabel!
  @IBOutlet weak var clearButtonHeightConstraint: NSLayoutConstraint!
  @IBOutlet weak var clearButtonView: UIImageView!

  let coreDataStack = CoreDataStack()
  var liftEvents = [LiftEvent]()
  var isFilterViewOpen = false

  override func viewDidLoad() {

    let doneButton = UIBarButtonItem(title: "Done", style: .Plain, target: self, action: #selector(self.dismissLog(_:)))

    let filterImage = UIImage(named: "filter_icon")
    let filterButton = UIBarButtonItem(image: filterImage, style: .Plain, target: self, action: #selector(self.actionFilter))

    self.navItem.rightBarButtonItems = [doneButton, filterButton]

    let buttonTap = UITapGestureRecognizer(target: self, action: #selector(self.clearFilter))
    clearFilterButton.addGestureRecognizer(buttonTap)

    filterViewHeightConstraint.constant = 0.0
    clearButtonHeightConstraint.constant = 0.0

    super.viewDidLoad()
  }
+4
1

UINavigationBar VC translucent false , UINavigationBar.appearance()?

enter image description here

VC Top Bar VC.

enter image description here

0

Source: https://habr.com/ru/post/1652794/


All Articles