
hii,,
how can i set a function on press keyboard done button.

hello,
For making keyboard Done button press :-
import keyboard displacement by adding this line
#define kOFFSET_FOR_KEYBOARD 80.0
here you can set 80.0 according to your need
-(void)textFieldDidBeginEditing:(UITextField *)sender
{
if ([sender isEqual:TextField])
{
if (self.view.frame.origin.y >= 0)
{
[self setViewMovedUp:YES];
}
}
}
-(void)setViewMovedUp:(BOOL)movedUp
{
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.5];
CGRect rect = self.view.frame;
if (movedUp)
{
rect.origin.y -= kOFFSET_FOR_KEYBOARD;
rect.size.height += kOFFSET_FOR_KEYBOARD;
}
else
{
// revert back to the normal state.
rect.origin.y += kOFFSET_FOR_KEYBOARD;
rect.size.height -= kOFFSET_FOR_KEYBOARD;
}
self.view.frame = rect;
[UIView commitAnimations];
}
- (void)keyboardWillShow:(NSNotification *)notif
{
if ([TextField isFirstResponder] && self.view.frame.origin.y >= 0)
{
flag=YES;
[self setViewMovedUp:YES];
}
else if (![TextField isFirstResponder] && self.view.frame.origin.y < 0)
{
[self setViewMovedUp:NO];
}
}
- (void)viewWillAppear:(BOOL)animated
{
// register for keyboard notifications
[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector
(keyboardWillShow:)
name:UIKeyboardWillShowNotification object:self.view.window];
}
- (void)viewWillDisappear:(BOOL)animated
{
// unregister for keyboard notifications while not visible.
[[NSNotificationCenter defaultCenter]
removeObserver:self name:UIKeyboardWillShowNotification object:nil]; }
-(void) touchesBegan :(NSSet *) touches withEvent:(UIEvent *)event
{
//NSLog(@"%@",flag);
if (flag==TRUE)
{
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.5];
CGRect rect = self.view.frame;
rect.origin.y += kOFFSET_FOR_KEYBOARD;
rect.size.height -= kOFFSET_FOR_KEYBOARD;
self.view.frame = rect;
[UIView commitAnimations];
flag=FALSE;
}
[TextField resignFirstResponder];
[super touchesBegan:touches withEvent:event ];
}