zoukankan      html  css  js  c++  java
  • iOS开发 编辑框被系统弹出的软键盘遮挡问题

             我们在开发注冊界面的时候,最后几个注冊条件经常easy被系统弹出的键盘遮挡,例如以下图:


         能够看见,邮箱条件被遮挡掉了,怎么解决呢?我是通过UITextField的代理加计算偏移量:

    - (void)viewDidLoad
    {
        [super viewDidLoad];
    	// Do any additional setup after loading the view, typically from a nib.
    
        self.emailTextField.delegate = self;
    
    }
    
    - (void)textFieldDidBeginEditing:(UITextField *)textField{
    
        //  1.取得被遮挡的邮箱的textField的frame
        CGRect frame = self.emailTextField.frame;
        //  2.计算被遮挡的textField的bottom代表的高度(Y坐标) 与 能不被键盘遮挡的最大高度(Y坐标) 的距离
        int offset = frame.origin.y + 32 - (self.view.frame.size.height - 216);
        
        [UIView animateWithDuration:0.3 animations:^{
           
            if (offset > 0) {
                
                //  让整个view向上偏移差距
                self.view.frame = CGRectMake(0, -offset, self.view.frame.size.width, self.view.frame.size.height);
            }
        }];
        
    }
    
    - (void)textFieldDidEndEditing:(UITextField *)textField{
        
        [UIView animateWithDuration:0.3 animations:^{
        
            //  编辑结束后重置为原来的
            self.view.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);
        }];
    
    }
    
         结果图:


  • 相关阅读:
    windows下mysql多实例安装
    linux下mysql多实例安装
    redisAPI整理
    Flink
    Google Dremel架构
    Apache Kylin
    Phoenix概述
    SQL on Hadoop技术综述
    AES对称加密算法
    Hawq架构
  • 原文地址:https://www.cnblogs.com/hrhguanli/p/4041622.html
Copyright © 2011-2022 走看看