zoukankan      html  css  js  c++  java
  • 有关UITextField、UITextView 软键盘弹出遮盖等问题的处理

    。h文件中实现UITextFieldDelegate,UITextViewDelegate委托
    。m文件:
    如果只要简单实现编辑功能 实现UITextFieldDelegate的某些相关方法就行
    #pragma mark - UITextFieldDelegate method
    -(void)textFieldDidBeginEditing:(UITextField *)textField{//先于键盘通知事件执行
        editRect = textField.frame;
       
    }
    -(void)textFieldDidEndEditing:(UITextField *)textField{
     NSString *dd = @"dfdfd";
    }
    -(BOOL)textFieldShouldReturn:(UITextField *)textField{
        [textField resignFirstResponder];
        return YES;
    }

    在- (void)viewDidLoad中注册键盘通知事件:在ios4.0和5.0中都有用 通过测试模拟器的
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyBoardWillShow:) name:UIKeyboardWillShowNotification object:nil];//键盘将要显示的通知
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyBoardWillHidden:) name:UIKeyboardWillHideNotification object:nil];//键盘将要隐藏的通知

    -(void)keyBoardWillShow:(NSNotification *)notif{
        NSDictionary *info = [notif userInfo];

        NSValue *value = [info objectForKey:UIKeyboardFrameBeginUserInfoKey];
        CGSize keyboardSize = [value CGRectValue].size;
        //整个UIViewControll中加一个scrollView控件 然后再把各种控件放在其中就行
       
        NSTimeInterval animation = 0.50f;
        [UIView beginAnimations:@"animal" context:nil];
        [UIView setAnimationDuration:animation];
        CGRect scrollViewFrame = [mainScroll frame];
        scrollViewFrame.size.height -= (keyboardSize.height-48);//减去tabBar的高度
        CGRect content = [contentView frame];
        content.size.height += (keyboardSize.height-48);
        contentView.frame = content;
        mainScroll.frame = scrollViewFrame;
        [mainScroll scrollRectToVisible:editRect animated:YES];
       
        [UIView commitAnimations];
    }
    -(void)keyBoardWillHidden:(NSNotification *)notif{
        NSDictionary *info = [notif userInfo];
       
        NSValue *value = [info objectForKey:UIKeyboardFrameBeginUserInfoKey];
        CGSize keyboardSize = [value CGRectValue].size;
       
        NSTimeInterval animation = 0.50f;
        [UIView beginAnimations:@"animal" context:nil];
        [UIView setAnimationDuration:animation];
        CGRect scrollViewFrame = [mainScroll frame];
        scrollViewFrame.size.height += (keyboardSize.height-48);
        mainScroll.frame = scrollViewFrame;
        CGRect content = [contentView frame];
        content.size.height -= (keyboardSize.height-48);
        contentView.frame = content;
       
        [UIView commitAnimations];
    }
  • 相关阅读:
    Portal嵌入SAPUI5应用程序
    定义Portal显示规则
    定义SAP Portal Url别名
    SAP EP 设置Portal别名安全模式
    MES系统在小批量电子行业生产管理中的应用
    建智能工厂,可从这6个方面着手!
    APS系统对制造企业到底有多重要?看完这5点你就明白了
    新手入门必看:VectorDraw 常见问题整理大全(二)
    轻量级流程图控件GoJS示例连载(一):最小化
    小批量、多品种生产模式如何快速响应客户交期
  • 原文地址:https://www.cnblogs.com/cnsec/p/11515880.html
Copyright © 2011-2022 走看看