Friday, February 25, 2011

UIView Moved Up Example

//In main file you can declare method
BOOL flagTextEdit;

- (void)setViewMovedUp:(BOOL)movedUp{
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.3];

CGRect rect = self.view.frame;
if (movedUp)
{
rect.origin.y = self.view.frame.origin.y - 185;
}
else
{
rect.origin.y = self.view.frame.origin.y + 185;
}
self.view.frame = rect;
[UIView commitAnimations];
}

#pragma mark -
#pragma mark textField Methods

- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
if(flagTextEdit)
{
[self setViewMovedUp:NO];
}
flagTextEdit=NO;
return YES;
}

- (void)textFieldDidBeginEditing:(UITextField *)textField
{
if([textField isEqual:txtEmail] && !flagTextEdit)
{
[self setViewMovedUp:YES];
flagTextEdit=YES;
}

}

No comments:

Post a Comment