一,效果图。

二,代码。

ViewController.h

#import <UIKit/UIKit.h>

@interface ViewController : UIViewController
<UITextFieldDelegate> @end

ViewController.m

#import "ViewController.h"

#define  W [UIScreen mainScreen].bounds.size.width
#define H [UIScreen mainScreen].bounds.size.height @interface ViewController () @end @implementation ViewController - (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib. UITextField *field=[[UITextField alloc]initWithFrame:CGRectMake(100, 300, 50, 50)];
field.backgroundColor=[UIColor redColor];
field.delegate=self;
[self.view addSubview:field];
} #pragma -mark -UITextFieldDelegate
-(BOOL)textFieldShouldReturn:(UITextField *)textField
{
[textField resignFirstResponder]; //self.view 恢复原位
NSTimeInterval animationDuration=0.10f;
[UIView beginAnimations:@"ResizeForKeyboard" context:nil];
[UIView setAnimationDuration:animationDuration];
float width = W;
float height = H;
float Y = 0.0f;
CGRect rect=CGRectMake(0.0f,Y,width,height);
self.view.frame=rect;
[UIView commitAnimations]; return YES;
} -(BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
NSTimeInterval animationDuration=0.30f;
[UIView beginAnimations:@"ResizeForKeyboard" context:nil];
[UIView setAnimationDuration:animationDuration];
float width = W;
float height = H;
//上移100个单位,按实际情况设置
CGRect rect=CGRectMake(0.0f,-100,width,height);
self.view.frame=rect;
[UIView commitAnimations]; return YES;
} - (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
} @end

【代码笔记】iOS-屏幕根据键盘自动的变化高度的更多相关文章

  1. 【代码笔记】iOS-Label随字自动变大

    一,效果图. 二,工程图. 三, 代码. RootViewController.h #import <UIKit/UIKit.h> //添加HPGrowingTextView头文件 #im ...

  2. iOS屏幕适配-iOS笔记

    学习目标 1.[了解]屏幕适配的发展史 2.[了解]autoResizing基本用法 3.[掌握]autoLayout 的基本用法 4.[掌握]autoLayout代码实现 5.[理解]sizeCla ...

  3. 李洪强iOS开发之- 点击屏幕遮挡键盘

    李洪强iOS开发之- 点击屏幕遮挡键盘 实现的效果:  01 - 给当前的view添加点击事件,使点击屏幕的时候,让键盘退出 /** * 点击屏幕 隐藏键盘 * * @param tap */-(vo ...

  4. iOS屏幕尺寸和分辨率

    iOS平台家族成员主要包括iPhone.iPod Touch和iPad,但是各类设备的分辨率各不相同,目前存在的尺寸主要有: iOS设备的尺寸多种多样,此外,屏幕的分辨率也有多种,总结如下表所示: 其 ...

  5. 笔记-iOS 视图控制器转场详解(上)

    这是一篇长文,详细讲解了视图控制器转场的方方面面,配有详细的示意图和代码,为了使得文章在微信公众号中易于阅读,seedante 辛苦将大量长篇代码用截图的方式呈现,另外作者也在 Github 上附上了 ...

  6. ios键盘弹起 body的高度拉长,页面底部空白问题。ios软键盘将页面抵到上面后,关闭软键盘页面不回弹的问题。

    js 监听ios手机键盘弹起和收起的事件 /* js 监听ios手机键盘弹起和收起的事件 */ document.body.addEventListener('focusin', () => { ...

  7. iOS Swift WisdomKeyboardKing 键盘智能管家SDK

    iOS Swift WisdomKeyboardKing 键盘智能管家SDK [1]前言:    今天给大家推荐个好用的开源框架:WisdomKeyboardKing,方面iOS日常开发,优点和功能请 ...

  8. python,PyAutoGUI,设置鼠标键盘自动操作

    三个文件需在同一个文件夹下面,文件夹的位置无要求. 1.第一个文件,trial.py.python代码调用PyAutoGUI操作鼠标键盘,可以通过修改start_time和end_time来确定程序自 ...

  9. iOS屏幕适配

    ## iOS屏幕适配 ### iOS屏幕适配发展史 1> iPhone4以前(没有iPad) * 不需要屏幕适配 2> iPad.iPhone5等设备出现 * 需要做横竖屏适配 * aut ...

随机推荐

  1. tomcat服务的启动与隐藏启动(win)

    一:  tomcat的启动与隐藏启动 1. 正常启动:D:\apache-tomcat-8.5.24\bin中的   startup.bat  双击启动 2. 启动tomcat服务后,window下方 ...

  2. 解放双手 | Jenkins + gitlab + maven 自动打包部署项目

    前言 记录 Jenkins + gitlab + maven 自动打包部署后端项目详细过程! 需求背景 不会偷懒的程序员不是好码农,传统的项目部署,有时候采用本地手动打包,再通过ssh传到服务器部署运 ...

  3. 05-创建kubectl-kubeconfig文件

    本文档介绍创建 kubeconfig 文件 下载 kubectl $ wget https://dl.k8s.io/v1.6.0/kubernetes-client-linux-amd64.tar.g ...

  4. python并发编程之进程池,线程池concurrent.futures

    进程池与线程池 在刚开始学多进程或多线程时,我们迫不及待地基于多进程或多线程实现并发的套接字通信,然而这种实现方式的致命缺陷是:服务的开启的进程数或线程数都会随着并发的客户端数目地增多而增多, 这会对 ...

  5. 【xsy1061】排列 树状数组

    题目大意:给你一个$1$到$n$的排列,问是否存在一对数$a,b(1≤a,b≤n,a≠b)$满足$a+b$为偶数且$(a+b)/2$在$a$和$b$之间. 数据范围:$n≤3\times 10^{5} ...

  6. typescript-koa-postgresql 实现一个简单的rest风格服务器 —— 连接 postgresql 数据库

    接上一篇,这里使用 sequelize 来连接 postgresql 数据库 1.安装 sequelize,数据库驱动 pg yarn add sequelize sequelize-typescri ...

  7. [Umbraco] 开篇

    本人虽已不做网站好几年,但这一技能至今也未能抛弃.如今要让我去做一个企业级产品介绍网站,我会很头疼,很痛苦,想的简单或想的复杂都是一件不讨好的事情. 任何这类网站都想快速开发,不管是节约时间,节约成本 ...

  8. 课程一(Neural Networks and Deep Learning),第二周(Basics of Neural Network programming)—— 2、编程作业常见问题与答案(Programming Assignment FAQ)

    Please note that when you are working on the programming exercise you will find comments that say &q ...

  9. 设置JVM参数的几种方式解决java.lang.OutOfMemoryError:Java heap space

    一.首先给出查询当前JVM内存的代码: 下面是查询当前JVM 内存大小的代码,可以测试设置后JVM 的内存是否会变化.增加JVM 内存的配置项后,无需重新启动eclipse .具体的代码如下: pub ...

  10. MVC源码分析 - Action查找和过滤器的执行时机

    接着上一篇, 在创建好Controller之后, 有一个 this.ExecuteCore()方法, 这部分是执行的. 那么里面具体做了些什么呢? //ControllerBaseprotected ...