本文介紹了顯示 iphone 的鍵盤時調整 UIView 的大小,如何?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
我將向您展示一個眾所周知的 whatsapp 示例當您觸摸文本內部時,鍵盤會彈出,因此我必須向上移動或移動所有條并將視圖大小調整為一半,這樣我仍然可以看到我正在輸入的文本和發送按鈕
I will show you an example with the well known whatsapp When you touch inside the text the keyboard pops up , so I have to move or shift all that bar up and resize the view to half, so I can still see the text that I'm typing and the send button
第一階段:http://www.appbank.net/wp-content/uploads/2010/10/WhatsAppMessenger-18.jpg
第二階段:http://www.onetooneglobal.com/wp-content/uploads/2011/02/onetoone_whatsapp_2.png
實現這一目標的最佳方法是什么?
What would be the best way to achieve this?
推薦答案
#define kOFFSET_FOR_KEYBOARD 280.0
- (void)keyboardWillHide:(NSNotification *)notif {
[self setViewMoveUp:NO];
}
- (void)keyboardWillShow:(NSNotification *)notif{
[self setViewMoveUp:YES];
}
- (void)textFieldDidBeginEditing:(UITextField *)textField {
stayup = YES;
[self setViewMoveUp:YES];
}
- (void)textFieldDidEndEditing:(UITextField *)textField {
stayup = NO;
[self setViewMoveUp:NO];
}
//method to move the view up/down whenever the keyboard is shown/dismissed
-(void)setViewMoveUp:(BOOL)moveUp
{
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.3]; // if you want to slide up the view
[UIView setAnimationBeginsFromCurrentState:YES];
CGRect rect = self.view.frame;
if (moveUp)
{
// 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.
if (rect.origin.y == 0 ) {
rect.origin.y -= kOFFSET_FOR_KEYBOARD;
//rect.size.height += kOFFSET_FOR_KEYBOARD;
}
}
else
{
if (stayup == NO) {
rect.origin.y += kOFFSET_FOR_KEYBOARD;
//rect.size.height -= kOFFSET_FOR_KEYBOARD;
}
}
self.view.frame = rect;
[UIView commitAnimations];
}
試試這個方法.根據您的要求對其進行編輯.
Try this methods. Edit it according to your requirement.
這篇關于顯示 iphone 的鍵盤時調整 UIView 的大小,如何?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!