如何像在Messages.app中一样移动iPhone键盘?

时间:2012-03-22 03:07:43

标签: iphone objective-c ios

  

可能重复:
  iMessage Style Receding Keyboard in an iOS App

在iOS5消息应用程序中,您可以在键盘上向下滑动手指以使其上下移动。这也可以在AppStore中的iA Writer应用程序中完成。如何在代码中执行此操作,即访问和修改UIKeyboard的Y位置?

2 个答案:

答案 0 :(得分:9)

答案 1 :(得分:2)

没有方法可以做到这一点,但您可以直接修改键盘的框架:

UIWindow* tempWindow;

//Because we cant get access to the UIKeyboard throught the SDK we will just use UIView. 
//UIKeyboard is a subclass of UIView anyways
UIView* keyboard;

//Check each window in our application
for(int c = 0; c < [[[UIApplication sharedApplication] windows] count]; c ++)
{
    //Get a reference of the current window
    tempWindow = [[[UIApplication sharedApplication] windows] objectAtIndex:c];

    //Get a reference of the current view 
    for(int i = 0; i < [tempWindow.subviews count]; i++)
    {
        keyboard = [tempWindow.subviews objectAtIndex:i];

        if([[keyboard description] hasPrefix:@"(lessThen)UIKeyboard"] == YES)
        {
            //If we get to this point, then our UIView "keyboard" is referencing our keyboard.
        }
    }
}