some_id
some_id

Reputation: 29886

How to set the position of the UIKeyboard

I have a search bar which is at the bottom of the view.

How can I set the position of the UIKeyboard?

Upvotes: 0

Views: 1153

Answers (3)

kubi
kubi

Reputation: 49364

You cannot set the position of the keyboard, you can only ask the keyboard where it is and organize your other views appropriately.

// Somewhere you need to register for keyboard notifications

- (void)viewDidLoad {
    [super viewDidLoad];

    // Register for keyboard notifications
    NSNotificationCenter *defaultCenter = [NSNotificationCenter defaultCenter];
    [defaultCenter addObserver:self selector:@selector(keyboardWasShown:)
                          name:UIKeyboardDidShowNotification object:nil];
    //... do something
}

// At some point you need to unregister for notifications
- (void)viewWillHide {
    NSNotificationCenter *defaultCenter = [NSNotificationCenter defaultCenter];
    [defaultCenter removeObserver:self];
}

- (void)keyboardWasShown:(NSNotification*)aNotification
{
    // Caution, this notification can be sent even when the keyboard is already visible
    // You'll want to check for and handle that situation
    NSDictionary* info = [aNotification userInfo];

    NSValue* aValue = [info objectForKey:UIKeyboardFrameEndUserInfoKey];

    CGSize keyboardSize = [aValue CGRectValue].size;

    //... do something
}

Upvotes: 1

k-thorat
k-thorat

Reputation: 5123

use CGAffineTransform At least from what I have observed and tested that OS version before 4.0 needs to define the transform, from the os 4.0 and greater OS is taking care of keyboard positioning. that's why here I am checking for the systemVersion before setting Transform.

    if ([[[UIDevice currentDevice] systemVersion] floatValue] < 4.0) {
        CGAffineTransform translate = CGAffineTransformMakeTranslation(xx.0, yy.0);//use x,y values
        [self setTransform:translate];
    }

Upvotes: 2

nacho4d
nacho4d

Reputation: 45118

You don't set the position of the keyboard. The system will do it for you automatically.

What you need to do is to move your searchbar to a visible part using keyboard notifications

Upvotes: 1

Related Questions