Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have found the iPhone's keyboard bounds in the apple documentation, but I can't find the iPad's keyboard bounds. Could you please help me?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
618 views
Welcome To Ask or Share your Answers For Others

1 Answer

The entire answer in code looks like this. First you need to register for the notifications:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardDidShow:) name:UIKeyboardDidShowNotification object:nil];

and there are more here. Note that you'll need to get rid of them, too (use removeObserver).

Then you need a method that gets the notification to get the size. Note that the size is, at first, not rotated (since the UIWindow doesn't rotate. Its contents do).

- (void) keyboardDidShow:(NSNotification*)notification {
        CGRect keyboardFrame = [[[notification userInfo] objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue];
        NSLog(@"keyboard frame raw %@", NSStringFromCGRect(keyboardFrame));

        UIWindow *window = [[[UIApplication sharedApplication] windows]objectAtIndex:0];
        UIView *mainSubviewOfWindow = window.rootViewController.view;
        CGRect keyboardFrameConverted = [mainSubviewOfWindow convertRect:keyboardFrame fromView:window];
        NSLog(@"keyboard frame converted %@", NSStringFromCGRect(keyboardFrameConverted));
}

Obviously, if you have a reference to your mainSubviewOfWindow by some other means, use it.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...