1.) 键盘是一个 UIWindow,位置取决于应用程序的主窗口。
2.)您可以做的是,在通知UIKeyboardWillShowNotification
或UIKeyboardWillChangeFrameNotification
方法之一触发时,循环浏览窗口子视图以定位键盘。在我的一个应用程序中,我需要向键盘添加一个子视图。对于您的情况,您可以通过以下方式获取框架:
//The UIWindow that contains the keyboard view - It some situations it will be better to actually
//iterate through each window to figure out where the keyboard is, but In my applications case
//I know that the second window has the keyboard so I just reference it directly
UIWindow* tempWindow = [[[UIApplication sharedApplication] windows] objectAtIndex:1];
//Because we cant get access to the UIPeripheral throught the SDK we will just use UIView.
//UIPeripheral is a subclass of UIView anyways
UIView* keyboard;
//Iterate though each view inside of the selected Window
for(int i = 0; i < [tempWindow.subviews count]; i++)
{
//Get a reference of the current view
keyboard = [tempWindow.subviews objectAtIndex:i];
//Assuming this is for 4.0+, In 3.0 you would use "<UIKeyboard"
if([[keyboard description] hasPrefix:@"<UIPeripheral"] == YES) {
//Keyboard is now a UIView reference to the UIPeripheral we want
NSLog(@"Keyboard Frame: %@",NSStringFromCGRect(keyboard.frame));
}
}
3.)不完全确定这是可能的,但我给你提供的代码。keyboard
现在被转换为“UIView”,您可以对其应用自己的转换。
这可能不是most
优雅的解决方案,但它适用于我的情况。
希望这可以帮助 !