0

Any ideas how to show an image behind a navigation bar and also show the "full" navigation bar on scrolling down?

Thanks in advance!

enter image description here enter image description here

Community
  • 1
  • 1
artemchen
  • 149
  • 1
  • 12
  • Have a look here: https://stackoverflow.com/a/40670196/8918347 – Govind Kumawat Nov 20 '18 at 05:14
  • @artemchen Do u need the NavigationBar Hide/Show or Do u want the Function of NavigationBar in the Image ? – Vicky_Vignesh Nov 20 '18 at 05:19
  • `self.navigationController?.hidesBarsOnTap = true` – rptwsthi Nov 20 '18 at 05:23
  • Possible duplicate of [How to hide the navigation bar and toolbar as scroll down? Swift (like myBridge app)](https://stackoverflow.com/questions/40667985/how-to-hide-the-navigation-bar-and-toolbar-as-scroll-down-swift-like-mybridge) – rptwsthi Nov 20 '18 at 05:25

3 Answers3

1
navigationController?.hidesBarsOnSwipe = true

Simply you can do like this. I hope It will work.

rptwsthi
  • 10,094
  • 10
  • 68
  • 109
Ruban4Axis
  • 821
  • 6
  • 27
1

Your Reference Image can be achieved by using the below code. Here 180 is the header size of the TableView.With This condition scrollOffset > 180 you can change the UIColor of the NavigationBar elements.

func scrollViewDidScroll(_ scrollView: UIScrollView) {

    let scrollOffset = scrollView.contentOffset.y

    UIView.animate(withDuration: 0.1) {
         self.navigationView.alpha = scrollOffset > 180 ? 1 : 0
    }

}

In your Header of the TableView, you should assign the Desired Image as HeaderView.

Vicky_Vignesh
  • 584
  • 2
  • 14
1

You can add image in the title view of the navigation item in viewDidLoad() of the view controller

override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view.
    let image = UIImage(named: "YOURIMAGE")
    navigationItem.titleView = UIImageView(image: image)
}

And here is an example how you can do it with CGRect.

override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view.
    let imageView = UIImageView(frame: CGRect(x: 0, y: 0, width: 38, height: 38))
    imageView.contentMode = .ScaleAspectFit
    let image = UIImage(named: "YOURIMAGE")
    imageView.image = image
    navigationItem.titleView = imageView
}
iOS Geek
  • 4,825
  • 1
  • 9
  • 30