iOS get height of keyboard (notify changes when keyboard appears, changes and disappears)

  1. - (void)viewDidLoad

    {

        [super viewDidLoad];

        

        // Increase monitoring, receive a message when the keyboard appears or changes

        [[NSNotificationCenter defaultCenter] addObserver:self

                                                 selector:@selector(keyboardWillShow:)

                                                     name:UIKeyboardWillShowNotification

                                                   object:nil];

        

        // Increase monitoring, receive a message when the key exits

        [[NSNotificationCenter defaultCenter] addObserver:self

                                                 selector:@selector(keyboardWillHide:)

                                                     name:UIKeyboardWillHideNotification

                                                   object:nil];

        

        

    }


    // Called when the keyboard appears or changes

    - (void)keyboardWillShow:(NSNotification *)aNotification

    {

        // Get the height of the keyboard

        NSDictionary *userInfo = [aNotification userInfo];

        NSValue  *aValue = [userInfo  objectForKey : UIKeyboardFrameEndUserIn foKey ];

        CGRect keyboardRect = [aValue CGRectValue];

        float height = keyboardRect.size.height;

    }


    // Called when the key exits

    - (void)keyboardWillHide:(NSNotification *)aNotification

    {

        

    }


Guess you like

Origin blog.csdn.net/lichuanliangios/article/details/46044643