Convert UIKeyboardFrameEndUserInfoKey to View or Window Coordinates

前端 未结 3 2222
灰色年华
灰色年华 2020-12-14 01:15

For the constant UIKeyboardFrameEndUserInfoKey, in the Apple docs it says:

These coordinates do not take into account any rotation facto

3条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-14 02:12

    The first view should be your view. The second view should be nil, meaning window/screen coordinates. Thus:

    NSDictionary* d = [notification userInfo];
    CGRect r = [d[UIKeyboardFrameEndUserInfoKey] CGRectValue];
    r = [myView convertRect:r fromView:nil];
    

    Now you have the rect that the keyboard will occupy, in terms of your view. If your view is the current view controller's view (or a subview thereof), rotation and so forth are now accounted for.

提交回复
热议问题