5

I have a navigation bar that is fixed to the top of the window when scrolling. However, when I click an input and the keyboard pops up the fixed position nav moves and gets stuck in the wrong position. Any way to fix this?

Also, I cannot seem to close the keyboard by clicking outside of it.

iluvpinkerton
  • 3,058
  • 3
  • 14
  • 17
  • is it a navigation bar set in interface builder or a custom view? there's no way it can move if it's the default navigation bar – jere Sep 11 '12 at 21:14
  • You must have code that is run when the keyboard is shown. Please post that if you want us to help. Also, post any code that is run when the keyboard is hidden. And lastly, the keyboard is not supposed to close when you tap outside of it. – lnafziger Sep 11 '12 at 21:50
  • http://stackoverflow.com/questions/7970389/ios-5-fixed-positioning-and-virtual-keyboard and http://stackoverflow.com/questions/12550298/mobile-safari-ios-6-0-fixed-positioning-while-keyboard-showing might be helpful – sjobe Jan 01 '13 at 04:12
  • Keyboard won't autohide when you touch outside it. You will have to implement some callback to to this for you. One easy approach is to create an invisible (custom) button that fills in all the background area and triggers a methods in which you do: `[textField resignFirstResponder];` – gabriel_vincent May 15 '13 at 02:43

1 Answers1

0

I'm not sure why your nav bar would move. If you are subclassing or using a UINavigationControlller then the nav bar itself will be provided by default but you can always hide it. If you are not and just want just a UINavgivationBar and not the stack of view controllers that you get with the controller than its possible to move the frame. I suggest using a nav controller instead to ensure your bar won't ever move.

To address the keyboard not hiding when you click off. There is no "automatic" way to do this you must explicitly call the method resignFirstResponder on a saved reference to the textfield you clicked to make the keyboard appear. The best way to do this is create a NSMutableArray property and implement the UITextfieldDelegate in your view controller .h and put the method -(void)textfiedDidBeginEditing:(UITextfield *)textfield I'm your .m and add the textfied to the mutable array inside there. From there you need to decide how the user will dismiss the keyboard IE clicked the background. So the easiest way is to add a giant UIButton with no text to the background that calls a method that loops through that mutablearray and calls the resignFirstResponder on everything and clears the array when done.

or you can always change the keyboard type of the textfield to be one that has a done button.

The choice is yours!

anders
  • 4,168
  • 2
  • 23
  • 31