Reputation: 1
a view in my app roughly looks like this:
An UIImage, and beyond this, a TextView describing the image. - The text should be editable.
And now this is my question: When the user taps into the textfield, the appearend keyboard "lies over the text" (the user can't see, what he is writing). Is there an easy to implement possibility (I'm a newbie to XCode) to swith the text to the upper part of the page, while editing it (something like: "if keyboard appers replace image by text", "if keyboard dissapears undo"), such that the user can see the changes?
Thanks for your help, Max
Upvotes: 0
Views: 899
Reputation: 7963
- (void)textFieldDidBeginEditing:(UITextField *)textField
{
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDelegate:self];
[UIView setAnimationDuration:0.5];
[UIView setAnimationBeginsFromCurrentState:YES];
txtField.frame = CGRectMake(txtField.frame.origin.x, (txtField.frame.origin.y), txtField.frame.size.width,txtField.frame.size.height);
[UIView commitAnimations];
}
- (void)textFieldDidEndEditing:(UITextField *)textField
{
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDelegate:self];
[UIView setAnimationDuration:0.5];
[UIView setAnimationBeginsFromCurrentState:YES];
UIInterfaceOrientation des=self.interfaceOrientation;
if (des==UIInterfaceOrientationLandscapeLeft||des==UIInterfaceOrientationLandscapeRight)
{
txtField.frame=CGRectMake(500,250,97,37);
}
[UIView commitAnimations];
}
}
" Don't forget to given this in Vied DidLoad"
self.view.frame=[[UIScreen mainScreen]applicationFrame];
view.autoresizesSubviews=NO;
txtField.delegate=self;
Upvotes: 0
Reputation: 242
Firstly conform u are using Text Field or Text View, i m considering that u are using text Field
// #define kOFFSET_FOR_KEYBOARD 110.0 define this in the .m file and set its value accordingly
-(void)textFieldDidBeginEditing:(UITextField *)textField{
if(self.view.frame.origin.y >= 0)
[self setViewMoveUp:YES];
}
}
-(void)setViewMoveUp:(BOOL)moveUp{
CGRect rect = self.view.frame;
if(moveUp)
{
rect.origin.y -= kOFFSET_FOR_KEYBOARD;
rect.size.height += kOFFSET_FOR_KEYBOARD;
}
else
{
rect.origin.y += kOFFSET_FOR_KEYBOARD;
rect.size.height -= kOFFSET_FOR_KEYBOARD;
}
self.view.frame = rect;
}
Upvotes: 1
Reputation: 5540
do like this.When the delegate method called (i.e in did beginEditing method)
Write this code
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.25];
[self.view setFrame:CGRectMake(0,-20,320,400)];
[UIView commitAnimations];
Upvotes: 0