0

I want to change the navigation bar position. After changing the position my back button action is not working. Actually I have added the navigation bar in my custom view controller. I want to change the navigation bar Y position. If I give negative value, back button action is not working and it works for any positive values(0..n). How can I make the back button action after changing the negative values for the navigation bar position.

Screenshot

let bounds = self.navigationController!.navigationBar.bounds
self.navigationController?.navigationBar.frame = CGRect(x: 0, y: -50, width: bounds.width, height: bounds.height)
self.navigationController?.navigationBar.backgroundColor = UIColor.gray
let button =  UIButton(type: .custom)
button.addTarget(self, action: #selector(btnAction), for: .touchUpInside)

button.frame = CGRect(x:0, y:0, width:32, height:32)
button.backgroundColor = UIColor.green
let barButton = UIBarButtonItem(customView: button)
self.navigationController?.navigationItem.backBarButtonItem = barButton
Devan
  • 147
  • 1
  • 1
  • 8
  • Since you are not only moving the navigationBar by -50 pixel but also increase the height of the navigationBar by 50 pixel, I assume you want to move the content of the navigationBar 50 pixel to the top of the screen or what do you want to achieve? – Paul Schröder Dec 20 '19 at 13:36
  • @PaulSchröder, Updated my question. Actually I've set the navigation bar y position to -50 as per my requirement. The problem is now, back button action is not working. – Devan Dec 21 '19 at 16:06
  • @Devian, what do you want to achieve by doing this? As far as I know, the height of the navigation bar is only 44 Points. So by moving it -50 Point in y, it should be out of the visible area. – Paul Schröder Dec 22 '19 at 14:30

0 Answers0