Reputation: 17169
I have used the demonstration code Apple has in their docs here:
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
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
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