1

my code :

- (void)keyboardWillShow:(NSNotification *)notification {

    NSDictionary *userInfo = [notification userInfo];

    NSValue *aValue = [userInfo objectForKey:UIKeyboardFrameBeginUserInfoKey];

    CGRect keyboardRect = [aValue CGRectValue];

    float keyboardHight=keyboardRect.size.height;
}

I make a break point at this line(float keyboardHight=keyboardRect.size.height;) ,and print those variable and the result:

Printing description of userInfo:
{
    UIKeyboardAnimationCurveUserInfoKey = 7;
    UIKeyboardAnimationDurationUserInfoKey = "0.25";
    UIKeyboardBoundsUserInfoKey = "NSRect: {{0, 0}, {320, 216}}";
    UIKeyboardCenterBeginUserInfoKey = "NSPoint: {160, 676}";
    UIKeyboardCenterEndUserInfoKey = "NSPoint: {160, 460}";
    UIKeyboardFrameBeginUserInfoKey = "NSRect: {{0, 568}, {320, 216}}";
    UIKeyboardFrameChangedByUserInteraction = 0;
    UIKeyboardFrameEndUserInfoKey = "NSRect: {{0, 352}, {320, 216}}";
}
Printing description of aValue:
NSRect: {{0, 568}, {320, 216}}
Printing description of keyboardRect:
(CGRect) keyboardRect = origin=(x=3.0491553029449835E-314, y=5.6817549271743353E-322) size=(width=3.0509261527954335E-314, height=3.0491551606540775E-314)

Why [aValue CGRectValue] return a wrong result. It works on iphone5c but not works iphone5s. Any idea is OK. Thanks.

tom tan
  • 11
  • 2
  • That sounds impossible to me. Did you try `NLog(@"keyboardRect = %@", NSStringFromCGRect(keyboardRect)`? – tia Mar 04 '15 at 03:48
  • NSLog(@"keyboardRect = %@", NSStringFromCGRect(keyboardRect) print the right result,but NSLog(@"keyboardRect h= %f",keyboardRect.size.height) is " keyboardRect h= 0 " – tom tan Mar 04 '15 at 04:06

0 Answers0