ios3.2/4查找键盘窗口的方式改变了

http://gist.github.com/454844

实际上应该是键盘窗口的类发生了变化,由UIKeyboard变成了UIPeripheralHostView

 

- (void)someSetupMethod {
  [[NSNotificationCenter defaultCenter] addObserver:self
                                           selector:@selector(keyboardWillShow:)
                                               name:UIKeyboardWillShowNotification object:nil];
}

- (void)someTeardownMethod {
  [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillShowNotification object:nil];
}


- (void)keyboardWillShow {
  // We must perform on delay (schedules on next run loop pass) for the keyboard subviews to be present.
  [self performSelector:@selector(addHideKeyboardButtonToKeyboard) withObject:nil afterDelay:0]; 
}


- (void)addHideKeyboardButtonToKeyboard {
  
  // Locate non-UIWindow.
  UIWindow *keyboardWindow = nil;
  for (UIWindow *testWindow in [[UIApplication sharedApplication] windows]) {
    if (![[testWindow class] isEqual:[UIWindow class]]) {
      keyboardWindow = testWindow;
      break;
    }
  }
  if (!keyboardWindow) return;

  // Locate UIKeyboard.  
  UIView *foundKeyboard = nil;
  for (UIView *possibleKeyboard in [keyboardWindow subviews]) {

    // iOS 4 sticks the UIKeyboard inside a UIPeripheralHostView.
    if ([[possibleKeyboard description] hasPrefix:@"<UIPeripheralHostView"]) {
      possibleKeyboard = [[possibleKeyboard subviews] objectAtIndex:0];
    }                                                                                
    
    if ([[possibleKeyboard description] hasPrefix:@"<UIKeyboard"]) {
      foundKeyboard = possibleKeyboard;
      break;
    }
  }
  
  if (foundKeyboard) {
    // Add the button to foundKeyboard.
  }
  
}

你可能感兴趣的:(ios,windows)