1.添加委托UITextFieldDelegate

2.

-(BOOL)textFieldShouldReturn:(UITextField *)textField {
[textField resignFirstResponder];
return YES;
} //隐藏键盘
- (void)textFieldDidBeginEditing:(UITextField *)textField {
[self animateTextField: textField up: YES];
}
- (void)textFieldDidEndEditing:(UITextField *)textField {
[self animateTextField: textField up: NO];
}
- (void) animateTextField: (UITextField*) textField up: (BOOL) up {
const int movementDistance = ; // tweak as needed
const float movementDuration = 0.3f; // tweak as needed int movement = (up ? -movementDistance : movementDistance); [UIView beginAnimations: @"anim" context: nil];
[UIView setAnimationBeginsFromCurrentState: YES];
[UIView setAnimationDuration: movementDuration];
self.view.frame = CGRectOffset(self.view.frame, , movement);
[UIView commitAnimations];
}
 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyBoardWillShow:) name:UIKeyboardWillShowNotification object:nil];

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyBoardWillHide:) name:UIKeyboardWillHideNotification object:nil];

#pragma mark - 键盘处理
#pragma mark 键盘即将显示 - (void)keyBoardWillShow:(NSNotification *)note{ CGRect rect = [note.userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue];
CGFloat ty = - rect.size.height;
[UIView animateWithDuration:[note.userInfo[UIKeyboardAnimationDurationUserInfoKey] doubleValue] animations:^{
self.view.transform = CGAffineTransformMakeTranslation(, ty + kNavigationBarHeight);
}]; } #pragma mark 键盘即将退出 - (void)keyBoardWillHide:(NSNotification *)note{ [UIView animateWithDuration:[note.userInfo[UIKeyboardAnimationDurationUserInfoKey] doubleValue] animations:^{
self.view.transform = CGAffineTransformIdentity;
}];
}

ios开发 点击文本(TextField)输入的时候向上推以及输入之后恢复的动画的更多相关文章

  1. IOS开发UI基础文本属性Attributes

    文本属性Attributes 1.NSKernAttributeName: @10 调整字句 kerning 字句调整 2.NSFontAttributeName : [UIFont systemFo ...

  2. iOS开发中获取文本的宽高的方式

    /** 计算单行文字的size @parms  文本 @parms  字体 @return  字体的CGSize */ + (CGSize)sizeWithText:(NSString *)text ...

  3. iOS开发——点击图片全屏显示

    点击图片,全屏显示,然后再点击屏幕一下,返回. 没啥难的,直接上代码: // //  ViewController.m //  Demo-hehe // //  Created by yyt on 1 ...

  4. iOS开发进阶 - 富文本正则替换表情

    移动端访问不佳,请访问我的个人博客 最近写项目需要用到富文本解析字符串显示表情,下面是我使用正则替换实现富文本的方式,希望能帮助到大家 先上效果图和demo地址 实现过程中需要用到的知识点 NSReg ...

  5. iOS开发 点击某处横屏竖屏切换

    typedef NS_ENUM(NSInteger, UIInterfaceOrientation) { UIInterfaceOrientationUnknown            = UIDe ...

  6. iOS开发 点击跳转到App Store 或者 点击按钮去评价

    //跳转到应用页面 NSString *str = [NSString stringWithFormat:@"http://itunes.apple.com/us/app/id%d" ...

  7. iOS:iOS开发非常全的三方库、插件等等

    iOS开发非常全的三方库.插件等等 github排名:https://github.com/trending, github搜索:https://github.com/search. 此文章转自git ...

  8. iOS开发之资料收集

    github排名:https://github.com/trending, github搜索:https://github.com/search. 此文章转自github:https://github ...

  9. iOS开发 非常全的三方库、插件、大牛博客等等

    UI 下拉刷新 EGOTableViewPullRefresh- 最早的下拉刷新控件. SVPullToRefresh- 下拉刷新控件. MJRefresh- 仅需一行代码就可以为UITableVie ...

随机推荐

  1. LINQ操作符三:限制操作符

    where是限制操作符,它将过滤标准应用在序列上,按照提供的逻辑对序列中的数据进行过滤. where操作符不启动查询的执行.当开始对序列进行遍历时才开始执行,此时过滤条件将被应用到查询中. 示例: / ...

  2. FFmpeg API变化

    可以查看doc目录下的APIchanges和根目录下的Changelog 去掉了ffserver程序   'avcodec_register_all' is deprecated 还有av_regis ...

  3. hibernate不调用save也保存上了

    List<Instrument> insts = instService.search(search); if (insts.size() == 1) { Instrument inst ...

  4. Node.js连接postgres

    一.下载Node.js postgres驱动 Node.js里面没有postgres模块的,我们需要安装node-postgres模块. node-postgres模块的下载地址为:https://g ...

  5. linux下node-webkit安装vlc插件

    一.下载node-webkit 下载linux版本的node-webkit,网址如下:https://github.com/rogerwang/node-webkit.文件解压之后又如下几个文件,其中 ...

  6. 更改HDFS权限

    hdfs dfs -chmod -R 755 / 之前执行过这条语句,但是总是提示: 15/05/21 08:10:18 WARN util.NativeCodeLoader: Unable to l ...

  7. C的内存四大区

    前提 看视频得来的内容,只知道不止4个区,但主要是这4个区. 四区 静态区 用于存放所有的全局变量和静态变量. ; //静态区 int main(){ ; //静态区 ; } 代码区 就是存放程序的执 ...

  8. 【Java面试题】24 sleep() 和 wait() 有什么区别? 详细解析!!!!

    第一种解释: 功能差不多,都用来进行线程控制,他们最大本质的区别是:sleep()不释放同步锁,wait()释放同步缩.         还有用法的上的不同是:sleep(milliseconds)可 ...

  9. [转]oracle存储过程、声明变量、for循环

    oracle存储过程.声明变量.for循环 1.创建存储过程 create or replace procedure test(var_name_1 in type,var_name_2 out ty ...

  10. Ubuntu Server 下的网络配置

    $ ifconfig 配置DHCP客户端$ sudo vi /etc/network/interfaces加入 iface eth0 inet dhcp 配置静态IP地址$ sudo vi /etc/ ...