2012-07-22 17 views
1

每個控制動作我實現了從一個堆棧溢出回答這個功能,第一個答案Move view when so that keyboard does not hide text field鑑於iPad上向上移動,但不能在iPhone上

//method to move the view up/down whenever the keyboard is shown/dismissed 
-(void)setViewMovedUp:(BOOL)movedUp 
{ 
    [UIView beginAnimations:nil context:NULL]; 
    [UIView setAnimationDuration:0.3]; // if you want to slide up the view 

    CGRect rect = self.view.frame; 
     if (movedUp) 
    { 
     // 1. move the view's origin up so that the text field that will be hidden come above the keyboard 
     // 2. increase the size of the view so that the area behind the keyboard is covered up. 
     rect.origin.y -= kOFFSET_FOR_KEYBOARD; 
     rect.size.height += kOFFSET_FOR_KEYBOARD; 
    } 
    else 
    { 
     // revert back to the normal state. 
     rect.origin.y += kOFFSET_FOR_KEYBOARD; 
     rect.size.height -= kOFFSET_FOR_KEYBOARD; 
    } 
    self.view.frame = rect; 

    [UIView commitAnimations]; 
} 

現在它在iPad上的偉大工程。我有一個文本框和旁邊的一些按鈕,並在它上面有一個聊天的文本視圖。您使用文本框鍵入您的聊天。在iPhone上,它會移動您輸入的文本框和按鈕,但不會移動文本視圖。實際上它保持覆蓋大部分窗口,並且按鈕在其中間的頂部移動。

現在我只是在今晚創建了iphone故事板視圖(現在有一個視圖),並將我的所有控件連接到它在ipad上工作。現在該程序仍然可以在ipad上正常工作,甚至可以在顯示鍵盤上移動視圖。但在iphone上它移動了除主控臺之外的所有東西,一個UITextView。哪一點是壞的一點是能夠閱讀文本,而你鍵入:)另外我想理解這裏的理論。看來如果我將視圖定義爲一個矩形並將其移動到某個數字(如250),它應該全部移動。也許有更好的方法來做到這一點,比如首先獲得鍵盤大小,但我仍然期望它能夠移動到那個高度。

邁克

回答

1

我增加了對人像和風景,但修復是如果iPod的主控制檯(TextView的),它是在縱向的位置(我唯一的iPod取向)的向上和向下復位後,我感動框架。整個看法被移動,所以我可以將它設置爲相同的位置,它將翻譯上下移動。:

double tall = 88; 
if(![self isTall]) 
tall =0; 
if (movedUp) 
{ 
// 1. move the view's origin up so that the text field that will be hidden come above the keyboard 
// 2. increase the size of the view so that the area behind the keyboard is covered up. 
rect.origin.y -= kOFFSET_FOR_KEYBOARD; 
rect.size.height += kOFFSET_FOR_KEYBOARD; 
self.view.frame = rect; 
if (IDIOM != IPAD) 
self._mainConsole.frame = CGRectMake(5, 5, 310, 379 + tall); 
} 
else 
{ 
// revert back to the normal state. 
rect.origin.y += kOFFSET_FOR_KEYBOARD; 
rect.size.height -= kOFFSET_FOR_KEYBOARD; 
self.view.frame = rect; 
if (IDIOM != IPAD) 
self._mainConsole.frame = CGRectMake(5, 5, 310, 379 + tall); 
} 
相關問題