English 中文(简体)
iPad 拆开键盘
原标题:iPad split-keyboard

我正在创建一个类似于 iPad s iMessage 应用程序的应用程序, 用于发送消息。 因此在显示键盘时, 在信件视图的底部有一个输入视图, 以及输入辅助视图。 当键盘在对接或撤消时显示键盘时, 也必须对信件视图进行适当调整大小 。

我的问题是,来自UIKeyboard WillChangeFrame通知的通知数据不一致。

首先,有三种方法用户可以取消键盘:

  1. Press-and-hold the lower right key, then slide up
  2. Press-and-hold the lower right key, when the menu pops up, select "undock"
  3. Press-and-hold the lower right key, when the menu pops up, select "split"

对于第1个案例,来自UIKeyboard WillC changeFrame通知的通知数据是一致的。以下是数据:

userInfo = {
    UIKeyboardFrameBeginUserInfoKey = "NSRect: {{0, 0}, {768, 304}}";
}

对于第2和第3个案例,数据不一致, 这是我收到的:

userInfo = {
    UIKeyboardAnimationCurveUserInfoKey = 0;
    UIKeyboardAnimationDurationUserInfoKey = "0.25";
    UIKeyboardBoundsUserInfoKey = "NSRect: {{0, 0}, {768, 304}}";
    UIKeyboardCenterBeginUserInfoKey = "NSPoint: {384, 872}";
    UIKeyboardCenterEndUserInfoKey = "NSPoint: {384, 1136}";
    UIKeyboardFrameBeginUserInfoKey = "NSRect: {{0, 0}, {768, 304}}";
    UIKeyboardFrameChangedByUserInteraction = 0;
    UIKeyboardFrameEndUserInfoKey = "NSRect: {{0, -264}, {768, 304}}";
}

奇怪的是当我听到UIKeyboard DidedC changeFrame通知第2或第3号案件,

userInfo = {
    UIKeyboardFrameBeginUserInfoKey = "NSRect: {{0, 0}, {768, 304}}";
}

通知数据为何不同?有没有人找到清晰的方法来检测断键器事件?

最佳回答

没有明确的方法没有。

我接下来要解决这个麻烦:

  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;

我更新了我的gist 。 使用转换矩形方法。

问题回答

这是一个有点黑客化的,但可靠的方法来确定键盘是否被分割。

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;

显然,为了使这项工作发挥作用,您需要一个 UIText 字段/ UITextView, 配有非nil < code> inputAccessoryView (您可以为此使用空视图) 。

注: text Field.intputAccessoryView. superview 的行为相当脆弱,通常取决于键盘在拨打 superview 之前曾显示过一次。此外,为了通过 AppStore 提交程序,我从私人类名称中删除了 UI 前缀。这不是一个保证苹果不会标记您的应用程序,但这个方法以前已被成功使用 。

我只在iOS7上测试过它,但如果它对其他版本的iOS类似方法不起作用,则可以使用。





相关问题
Asynchronous request to the server from background thread

I ve got the problem when I tried to do asynchronous requests to server from background thread. I ve never got results of those requests. Simple example which shows the problem: @protocol ...

objective-c: Calling a void function from another controller

i have a void, like -(void) doSomething in a specific controller. i can call it in this controller via [self doSomething], but i don t know how to call this void from another .m file. I want to call ...

ABPersonViewController Usage for displaying contact

Created a View based Project and added a contact to the AddressBook using ABAddressBookRef,ABRecordRef now i wanted to display the added contact ABPersonViewController is the method but how to use in ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

NSUndoManager and runModalForWindow:

I have a simple Core Data app which displays a list of entities in the main window. To create or add new entities, I use a second modal window with a separate managed object context so changes can be ...

NSMutableArray values becoming "invalid"

I m trying to show a database information in a tableview and then the detailed information in a view my problem is as follow: I created a NSMutableArray: NSMutableArray *myArray = [[NSMutableArray ...

iPhone numberpad with decimal point

I am writing an iPhone application which requires the user to enter several values that may contain a decimal point (currency values, percentages etc.). The number of decimal places in the values ...

热门标签