2

I have a few textfield's which are obscured by the keyboard when visible. I think I will need to shift view up when the keyboard is visible. How do I detect this?

swiftBoy
  • 33,793
  • 26
  • 129
  • 124
  • look at this post http://stackoverflow.com/questions/5965580/move-view-when-so-that-keyboard-does-not-hide-text-field – iArezki Dec 27 '12 at 09:42
  • @Kalpesh what is your code supposed to do? please provide description if you are intending to help, not just code that I am assumed to understand as im a novice. – user1931721 Dec 27 '12 at 09:51
  • just have look on this [solution](http://stackoverflow.com/questions/1126726/how-to-make-a-uitextfield-move-up-when-keyboard-is-present) – swiftBoy Dec 27 '12 at 09:58

5 Answers5

3

Check Managing the Keyboard - Receiving Keyboard Notifications section in Text, Web, and Editing Programming Guide for iOS: http://developer.apple.com/library/ios/#documentation/StringsTextFonts/Conceptual/TextAndWebiPhoneOS/KeyboardManagement/KeyboardManagement.html

When the keyboard is shown or hidden, iOS sends out the following notifications to any registered observers:

UIKeyboardWillShowNotification UIKeyboardDidShowNotification UIKeyboardWillHideNotification UIKeyboardDidHideNotification

Valerii Pavlov
  • 1,896
  • 19
  • 30
1

Perhaps you are looking for this to detect when the keyboard will be made visible on a textfield being editable.

akdsouza
  • 1,955
  • 2
  • 21
  • 39
  • you will need to set your textfields delegate in say the xib or via code if created programmaticaly and then implement the didBeginEditing delegate. It'll fire everytime your textfields begin editing. You can then check for which textfields are being hidden by the keyboard and move your container view upwards appropriately. – akdsouza Dec 27 '12 at 09:41
  • Bingo! the delegate was what I was looking for. I can now handle the view movement for all obscured keyboards. Thank you. – user1931721 Dec 27 '12 at 09:57
  • How to move your container view upwards appropriately? – bheatcoker Jul 09 '15 at 11:13
0

I think you are new in iOS.

I think your view is contain 5 - 10 textfield and use will input text one by one.

If this is your situation than put all your textfield in a uiscrollview so u can scroll up down when needed.

this is normal method which all programer follow.

If this is your situation than tell me I may give you some example link.

akdsouza
  • 1,955
  • 2
  • 21
  • 39
CRDave
  • 9,133
  • 5
  • 38
  • 58
  • have you ever used toolbar with next previous button? – CRDave Dec 27 '12 at 09:48
  • ya because u r not using uiscrollview. so u must have some way to go up and down and toolbar with next previous button can provide u. see this example of toolbar http://www.nwmobiledev.com/iphone-keyboard-toolbar-with-next-previous-and-hide-buttons/ – CRDave Dec 27 '12 at 09:52
  • i think that is a lot of additional work to be honest. i'm looking for a simpler way to auto detect the textfield's editing mode. – user1931721 Dec 27 '12 at 09:56
  • yes u can detect edit mode that is very simple as kevin said. the problem occur if u have more textfield such that when u r editing a textfield and next textfield is hidden under keyboard. – CRDave Dec 27 '12 at 10:01
0
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.35f]; 
CGRect frame = self.view.frame; 
frame.origin.y = -60; 
[self.view setFrame:frame]; 
[UIView commitAnimations];
[textField resignFirstResponder];

you can use this code for moving the view up and down if you want the set the view on same position as it was before then you can use the same code

[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.35f]; 
CGRect frame = self.view.frame; 
frame.origin.y = 0; 
[self.view setFrame:frame]; 
[UIView commitAnimations];
[textField resignFirstResponder];

but diffrent value of y you can play with the frame.origin.y and adjust it accordingly..

Ahsan
  • 827
  • 6
  • 10
0

This document has all the code that you require

Read Q
  • 1,035
  • 2
  • 12
  • 25