Josh Kahane
Josh Kahane

Reputation: 17169

Move View When Keyboard Appears - Only Upon Editing?

I have used the demonstration code Apple has in their docs here:

http://developer.apple.com/library/ios/#documentation/StringsTextFonts/Conceptual/TextAndWebiPhoneOS/KeyboardManagement/KeyboardManagement.html#//apple_ref/doc/uid/TP40009542-CH5-SW7

To have my view move accordingly depending on which textField is being edited. It works great, my view moves as I expect, except for one thing.

My issue is, I can select a textField and it will only move the view up when I begin typing and not when I actually select the textField.

I am literally using identical code as in the docs (follow the link above). Quite frustrating, I can't see what would cause this. Thanks.

Upvotes: 0

Views: 319

Answers (2)

j9suvak
j9suvak

Reputation: 1120

I had this trouble too. In keyboardWasShown, the Apple documentation says:

 if (!CGRectContainsPoint(aRect, activeField.frame.origin) 

I used:

if (activeField == myTextField)

Here's the long version of the answer: moving content located under the keyboard

Upvotes: 0

Mohammad Kamar Shad
Mohammad Kamar Shad

Reputation: 6067

Here is The Logic See.

1)You need a Flag Value Set TRUE initially in ViewDidLoad or viewWillAPpear. suppose isNeedToMove is that Flag value.

you need to Implement these methods in Your Code,for using them don't forget to Adopt the protocol UITextFieldDelegate in your UIViewcontroller.h class.

EDIT:Here I have Chnaged The Code AS you mentioned in yOur Comment You needed to move That UIView on just Touching the TextFIeld.See Here below Is The Logic With SOme Code.

addTarget To the TextField in ViewDiodiLoad

- (void)viewDidload
{
 [touchyTextField addTarget:self
                    action:@selector(yourDesiredMethod)
          forControlEvents:UIControlEventTouchDown];
}

-(void)yourDesiredMethod
{
if(isNeedToMove)//this Flag Avoid The unnecessary move call.
{
 //here call the method which Move The UIview
 }
}


- (BOOL)textFieldShouldReturn:(UITextField*)textField
{

[textField resignFirstResponder];
//here call the method which move UIView to its actual position.
 isNeedToMove= TRUE;
 return YES;

}

I hope you may get Some idea .

Upvotes: 1

Related Questions