显示 iphone 的键盘时调整 UIView 的大小,如何?

resize UIView when showing the keyboard for iphone, how to?(显示 iphone 的键盘时调整 UIView 的大小,如何?)
本文介绍了显示 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 的大小,如何?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Pushing UIViewController above UITabBar(将UIView控制器推送到UITabBar上方)
java.lang.IllegalStateException: SimpleTypeImpl should not be created for error type(异常:不应为错误类型创建SimpleTypeImpl)
How to send an image with custom keyboard iOS(如何使用自定义键盘IO发送映像)
Capture barcode reader (keyboard-wedge) events from javascript(从Java脚本捕获条形码读取器(键盘按钮)事件)
Android IllegalArgumentException: The tag for fragment_XXX is invalid. Received: layout-sw600dp/fragment_XXX_0(Android IlLegalArgumentException:Fragment_XXX的标签无效。收到:Layout-sw600dp/Fragment_XXX_0)
NavigationView: custom item layout with app:actionLayout how to?(NavigationView:使用APP:ActionLayout自定义项目布局如何?)