博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
ios-利用键盘通知处理键盘出现时遮挡控件问题
阅读量:4947 次
发布时间:2019-06-11

本文共 1759 字,大约阅读时间需要 5 分钟。

-(void)viewDidLoad {NSNotificationCenter *center = [NSNotificationCenter defaultCenter];        //注册键盘显示通知    [center addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];    //注册键盘隐藏通知    [center addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];}-(void)viewDidDisappear:(BOOL)animated{    //移除通知    [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillShowNotification object:nil];    [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillHideNotification object:nil];}- (void) keyboardWillShow:(NSNotification *) notification{        NSDictionary *info;    CGSize kbSize;    double kbheight;    CGFloat Oversize;    double duraction;        info = notification.userInfo;    kbSize = [[info objectForKey: UIKeyboardFrameEndUserInfoKey]CGRectValue].size;    kbheight = kbSize.height;        Oversize = (self.view.frame.size.height - kbheight) - (textfield.frame.origin.y + textfield.frame.size.height+5);        duraction =  [[info objectForKey:UIKeyboardAnimationDurationUserInfoKey] doubleValue];        if (Oversize < 0){        [UIView animateWithDuration: duraction animations:^{            self.view.frame = CGRectMake(0.0f, Oversize, self.view.frame.size.width, self.view.frame.size.height);        }];    }}-(void) keyboardWillHide:(NSNotification *) notification{        double duraction = [[notification.userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey] doubleValue];        [UIView animateWithDuration:duraction animations:^{        self.view.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);    }];}

 

转载于:https://www.cnblogs.com/cccliche/p/9123854.html

你可能感兴趣的文章
并发编程之多进程篇之一
查看>>
AutoMapper搬运工之自定义映射
查看>>
EL表达式详解
查看>>
xpath提取多个标签下的text
查看>>
alias导致virtualenv异常的分析和解法
查看>>
html和jsp的区别及优缺点
查看>>
排列组合
查看>>
动态规划
查看>>
Spring的初始化:org.springframework.web.context.ContextLoaderListener
查看>>
Qt编写串口通信程序全程图文讲解(完整)
查看>>
Excel数据生成Sql语句的方法
查看>>
java中random()函数用法介绍
查看>>
C# OLEDB读取EXCEL表格时,某些字段为空解决方法
查看>>
Web前端开发HTML基础(1)
查看>>
bzoj1934: [Shoi2007]Vote 善意的投票
查看>>
The New Methodology新方法论
查看>>
Linux 进程管理剖析: Linux 同步方法剖析 内核原子,自旋锁和互斥锁
查看>>
day06---selenium剩余操作和自动登录
查看>>
Promise 基础学习
查看>>
干货!前端常见兼容性问题
查看>>