iPad split-keyboard

前端 未结 2 943
一生所求
一生所求 2020-12-31 16:38

I am creating an app similar to the iPad\'s iMessage app that does messaging. So there is an input view anchored at the bottom of the message view and input accessory view

2条回答
  •  轮回少年
    2020-12-31 17:15

    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.

提交回复
热议问题