iPad split-keyboard

百般思念 提交于 2019-11-30 09:06:58
Bimawa

No clear method haven't.

i resolve this trouble in next steps:

  1. Get current orientation.
  2. If orientation is Landscape then i get height of UIKeyboardFrameEndUserInfoKey. it must equals to 216. It means keyboard is Split mode, Else not;
  3. If orientation is Portrait then i get height of UIKeyboardFrameEndUserInfoKey. it must equals to 216. It means keyboard is Split mode, Else not;

I update my gist for example. With convertRect method.

This is a somewhat hacky, but reliable way to determine whether the keyboard is split.

NSArray *classPath = @[
  @"KeyboardAutomatic",
  @"KeyboardImpl",
  @"KeyboardLayoutStar",
  @"KBKeyplaneView",
  @"KBSplitImageView"
];
UIView *splitView = textField.inputAccessoryView.superview;
for (NSString *className in classPath) {
  for (UIView *subview in splitView.subviews) {
    if ([NSStringFromClass([subview class]) rangeOfString:className].location != NSNotFound) {
      splitView = subview;
      break;
    }
  }
}
BOOL isSplit = [splitView.subviews count] > 1;

Obviously in order for this to work you need a UITextField/UITextView with a non-nil inputAccessoryView (you can just use an empty view for that).

Note: The behavior of textField.inputAccessoryView.superview is quite finicky, and usually depends on the keyboard having been displayed once before calling superview. Also to pass the App Store submission process I removed the 'UI' prefix from the private class names. That's not a guarantee Apple will not flag your app, but this approach has been used successfully before.

I've only tested it on iOS7 but if it doesn't work on other versions of iOS similar approaches could be used.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!