Pages

Showing posts with label Keyboard. Show all posts
Showing posts with label Keyboard. Show all posts

Thursday, October 3, 2013

Hide Keyboard for presentViewController

Hi, i found an issue that if you are using presentViewController then resignFirstResponder doesn't hide the keyboard. We can follow the below method for hiding keyboard

Just write the below code and add resignFirstResponder. it should work then 
-(BOOL)disablesAutomaticKeyboardDismissal{
    return NO;

}

Tuesday, August 13, 2013

Move View while keyboard appears

There are some cases, when you want to type in UITextField and also want to show that in screen. But keyboard hides your UITextField. You can use the following code for this


-(void)setViewMovedUp:(BOOL)movedUp
{
    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:0.3]; // if you want to slide up the view
    
    CGRect rect = self.completeSingleView.frame;
    if (movedUp)
    {
        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.completeSingleView.frame = rect;
    
    [UIView commitAnimations];
}

Now How to Use this

First of all set the <UITextFieldDelegrate> in class ".h" file and set UITextField delegate to self, Like if we have some textfield with name "loginID" then set the delegate to self like below

loginID.delegate = self;

Now use the below code, which call the upper function 

-(void)textFieldDidEndEditing:(UITextField *)sender
{
    if  (self.completeSingleView.frame.origin.y < 0)
        [self setViewMovedUp:NO];
}
-(void)textFieldDidBeginEditing:(UITextField *)sender
{
    if  (self.completeSingleView.frame.origin.y >= 0)
        [self setViewMovedUp:YES];
}



Friday, January 18, 2013

How to Hide Keyboard in xCode/swift

Objective C:
Just declare the function as mentioned below:

Declare function for TextHolder in "Did End Exit" event as below: in (.h) file

- (IBAction)editingCompleted:(id)sender;


now define function in (.m) file as below:


- (IBAction)editingCompleted:(id)sender {
    [sender resignFirstResponder]; // Here sender is the TextHolder, which text you can print also as sender.text
}


Always use resignFirstResponder with TextHolder, for which keyboard needs to hide.

Swift:
Declare function for TextHolder for "Did End On Exit"


@IBAction func editingCompleted(sender: UITextField) {
        sender.resignFirstResponder()

 }