博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
iOS键盘弹出完美移动控件
阅读量:2431 次
发布时间:2019-05-10

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

添加监听(最好放在ViewWillAppear里, 在视图将要消失时移除监听)

这里监听键盘Frame的变化而不是监听键盘的显示和隐藏

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardFrameChange:) name:UIKeyboardWillChangeFrameNotification object:nil];

实现方法
_toolBar是要移动的View控件
#pragma mark - 键盘Frame改变时调用-(void)keyboardFrameChange:(NSNotification *)note{    CGFloat durtion = [note.userInfo[UIKeyboardAnimationDurationUserInfoKey] floatValue];    CGRect frame = [note.userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue];    if (frame.origin.y == self.view.frame.size.height)    {        // 没有弹出键盘        [UIView animateWithDuration:durtion animations:^{            _toolBar.transform = CGAffineTransformIdentity;        }];    }    else    {        // 弹出键盘        // 工具条向上移动键盘的高度        [UIView animateWithDuration:durtion animations:^{            _toolBar.transform = CGAffineTransformMakeTranslation(0, -frame.size.height);        }];    }}

转载地址:http://ejtmb.baihongyu.com/

你可能感兴趣的文章
CF402E / 403C
查看>>
cf404b
查看>>
cf404c
查看>>
cf404d
查看>>
武大网络预赛 Problem 1537 - A - Stones I
查看>>
武大网络预赛 Problem 1545 - I - Twenty-four
查看>>
ZOJ Problem Set - 3772 Calculate the Function 矩阵+线段树
查看>>
ZOJ Problem Set - 3768 Continuous Login
查看>>
某山面试 3、实现如下函数:
查看>>
malloc的小知识
查看>>
UVALive 6755 - Swyper Keyboard
查看>>
uva_11029 Leading and Trailing 快速幂 数的n次方前几位
查看>>
uva10023 手算开方的方法
查看>>
uva11027
查看>>
欧拉函数——从容斥定理和积性函数的性质谈开
查看>>
容斥原理 带禁止位的排列
查看>>
模拟带Servlet技术的HTTP服务器的Java实现
查看>>
第一个JSP程序(JSP入门)
查看>>
JSP语法简介
查看>>
JavaBean入门与简介
查看>>