键盘弹出后上提view隐藏后下拉view还原并修改scroll过程中旋转屏幕到竖屏view显示错误
1,注册键盘相应事件
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
2,移除相应事件
- (void)viewDidDisappear:(BOOL)animated{
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
3,控制view高度
-(void)hidenKeyboard
{
[self.accountFieldItem resignFirstResponder];
[self.passwordFieldItem resignFirstResponder];
}
-(void)nextOnKeyboard:(UITextField *)sender
{
if (sender == self.accountFieldItem)
{
[self.passwordFieldItem becomeFirstResponder];
}
else if (sender == self.passwordFieldItem)
{
[self hidenKeyboard];
}
}
- (void)keyboardWillShow:(NSNotification *)notification {
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
if (self.interfaceOrientation != UIDeviceOrientationPortrait &&
self.interfaceOrientation != UIDeviceOrientationPortraitUpsideDown){
[self.scrollView setScrollEnabled:YES];
[self.scrollView setShowsVerticalScrollIndicator:YES];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.5];
[self.scrollView setFrame:CGRectMake(CGRectGetMinX(self.view.bounds) + CGRectGetWidth(self.view.bounds)/4 - 20, 0, CGRectGetWidth(self.view.bounds)/2 +40,self.view.frame.size.height)];
[UIView commitAnimations];
}else
{
[self.scrollView setScrollEnabled:NO];
[self.scrollView setShowsVerticalScrollIndicator:NO];
[self.accountFieldItem becomeFirstResponder];
self.scrollView.frame = CGRectMake(CGRectGetMinX(self.view.bounds) + 20,CGRectGetMinY(self.view.bounds) + 25,CGRectGetWidth(self.view.bounds) - 40,self.view.frame.size.height);
}
}
else
{
if (self.interfaceOrientation != UIDeviceOrientationPortrait &&
self.interfaceOrientation != UIDeviceOrientationPortraitUpsideDown){
[self.scrollView setScrollEnabled:YES];
[self.scrollView setShowsVerticalScrollIndicator:YES];
}
else
{
[self.scrollView setScrollEnabled:NO];
[self.scrollView setShowsVerticalScrollIndicator:NO];
}
}
}
- (void)keyboardWillHide:(NSNotification *)notification {
[self.scrollView setScrollEnabled:NO];
[self.scrollView setShowsVerticalScrollIndicator:NO];
[self.scrollView setContentOffset:CGPointMake(0, 0) animated:NO];//将scroll滚动拉动起始位置,然后旋转成竖屏后就不会出现view显示错误,直接从scrollview顶部开始显示,否则又可以只显示了半截或者更少视图
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
if (self.interfaceOrientation != UIDeviceOrientationPortrait &&
self.interfaceOrientation != UIDeviceOrientationPortraitUpsideDown){
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.5];
[self.scrollView setFrame:CGRectMake(CGRectGetMinX(self.view.bounds) + CGRectGetWidth(self.view.bounds)/4 - 20, CGRectGetMinY(self.view.bounds) + 25, CGRectGetWidth(self.view.bounds)/2 + 40,self.view.frame.size.height)];
[UIView commitAnimations];
}else
{
self.scrollView.frame = CGRectMake(CGRectGetMinX(self.view.bounds) + 20,CGRectGetMinY(self.view.bounds) + 25,CGRectGetWidth(self.view.bounds) - 40,self.view.frame.size.height);
}
}
}
键盘弹出后上提view隐藏后下拉view还原并修改scroll过程中旋转屏幕到竖屏view显示错误的更多相关文章
- 周记3——解决fixed属性在ios软键盘弹出后失效的bug
这周在做空间(“类似”qq空间)项目.首页是好友发表的说说,可以针对每条说说进行评论,评论框吸附固定在屏幕底部.此时,Bug来了...在ios上,软键盘弹出后fixed属性失效了.后来发现,ios绝大 ...
- Ionic3学习笔记(九)关于 Android 端软键盘弹出后界面被压缩的问题
本文为原创文章,转载请标明出处 今天做了一个如下图所示的页面. iOS 端毫无 bug,Android 端却出现了问题.当软键盘弹出后,Android 端的 tabs 移到了软键盘的上面,再仔细一看, ...
- KeyboardUtil【软键盘弹出后输入框上移一定的高度】
版权声明:本文为HaiyuKing原创文章,转载请注明出处! 前言 演示获取软键盘高度并保存,然后根据输入框的原有位置是否被软键盘挡住了,如果被挡住了则将整体页面上移一定的高度,当软键盘隐藏的时候再下 ...
- RecyclerView上拉隐藏Toolbar,下拉显示
RecyclerView下拉隐藏Toolbar,上拉显示效果图 先说个事:最近我准备做个开源的博客园android客户端!符合Google最新的material design设计风格的!不知道有没有小 ...
- dropload.js 上滑加载,下拉刷新
https://github.com/ximan/dropload dropload a javascript implementation of pull to refresh and up to ...
- select框默认样式去除(ie中隐藏默认下拉图标)
html代码 <select class="info-select"> <option selected="selected">1< ...
- Web 1三级联动 下拉框 2添加修改删除 弹框
Web 三级联动 下拉框 using System; using System.Collections.Generic; using System.Linq; using System.Web; u ...
- 隐藏AutoCompleteTextView下拉框的滚动条
最近做项目需要用到AutoCompleteTextView这个控件,而其下拉框的滚动条有点难看,于是想去掉.走了些弯路,终于弄通了. 首先先介绍一种不靠谱的方法:反射机制 为什么会有人想到用这个呢? ...
- 关于ListView中EditText在软键盘弹出后的焦点问题
转自:http://www.cnblogs.com/haofei/p/3305030.html 在ListView中,每次弹出软键盘后就会重新调用getView()方法,导致EditText失去焦点. ...
随机推荐
- OpenStack之虚机热迁移
OpenStack之虚机热迁移 最近要搞虚机的热迁移,所以也就看了看虚机迁移部分的内容.我的系统是CentOS6.5,此处为基于NFS共享平台的虚机迁移.有关NFS共享服务器的搭建可以看这里. Yak ...
- 静态文本框控件的美化CStatic
VC通用控件都是灰色,当对程序界面进行美化时,使用通用控件就和美化后的程序界面不搭配,在VB,C#中,可以很方便的更改控件背景颜色,但在VC中就不能,需要我们自己来完善这方面的功能.我在这只简单的介绍 ...
- mysql安装 以及跳过密码登录重设
修改MySQL的登录设置: vi /etc/my.cnf 在[mysqld]的段中加上一句:skip-grant-tables 例如: [mysqld] datadir=/var/lib/mysql ...
- redis linux 集群
redis集群:官方教程 步骤: 1.安装redis 2.修改配置文件redis.conf(集群所需基础配置) port 7000 cluster-enabled yes cluster-config ...
- maven学习(十四)——Eclipse中使用Maven插件
1.导入Maven项目 File→import
- 【bzoj4127】Abs 树链剖分+线段树
题目描述 给定一棵树,设计数据结构支持以下操作 1 u v d 表示将路径 (u,v) 加d 2 u v 表示询问路径 (u,v) 上点权绝对值的和 输入 第一行两个整数n和m,表示结点个数和操作数 ...
- 【Luogu】P2173网络(LCT)
题目链接 这次坑我的是与或的结合顺序…… 开十个LCT记录一下即可.以上. #include<cstdio> #include<cstring> #include<cst ...
- [luogu1707] 刷题比赛 [矩阵快速幂]
题面: 传送门 思路: 一眼看上去是三个递推......好像还挺麻烦的 仔细观察一下,发现也就是一个线性递推,但是其中后面的常数项比较麻烦 观察一下,这里面有以下三个递推是比较麻烦的 第一个是$k^2 ...
- 转载:LeetCode:5Longest Palindromic Substring 最长回文子串
本文转自:http://www.cnblogs.com/TenosDoIt/p/3675788.html 题目链接 Given a string S, find the longest palindr ...
- Python 读取 pkl文件
使用python 的cPickle 库中的load函数,可以读取pkl文件的内容 import cPickle as pickle fr = open('mnist.pkl') #open的参数是pk ...