2012-03-22 36 views
6

可能重複:
iMessage Style Receding Keyboard in an iOS App如何在Messages.app中移動iPhone鍵盤?

在iOS5的消息應用程序,您可以將您的手指按住鍵盤上滑動,把它上下。這也是在AppStore的iA Writer應用程序中完成的。我如何在代碼中這樣做,即訪問和修改UIKeyboard的Y位置?

+0

這是在這裏回答:http://stackoverflow.com/questions/7780753/imessage-style-receding-keyboard-in-an-ios-app – Ginny 2012-09-01 04:04:04

+0

是的,但它由CodaFi在這裏回答得更好。 @CodaFi,你應該真的把你的答案從這裏複製到這個被贊成的問題上,因爲那裏的答案可能會導致一些誤入歧途,以至於用DAKeyboardControl解決這個問題有多容易(也許還有其他問題,我還沒有嘗試過他們)。沒有什麼可以像一個#import加上一行代碼來做你所需要的。 – 2012-12-01 06:41:03

回答

9
+0

iOS7發佈之後,我還沒有找到好的項目來實現iOS6/7支持這個東西。 – derpoliuk 2014-03-04 11:54:37

+1

iOS 7發佈之後,不再需要這個了,因爲Apple已經在'UIScrollView' – 2016-01-23 14:31:11

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. 
     } 
    } 
} 
+0

爲什麼不使用-isKindOfClass:而不是-hasPrefix? – 2012-03-22 03:28:36

+0

這個AppStore合法嗎? – Snowman 2012-03-22 03:33:07

+0

@ RichardJ.RossIII,因爲isKindOfClass只會告訴你它是否是UIView,並且tempWindow.subviews返回的所有對象都是UIView對象。 – 2012-03-22 03:35:24