键盘弹出后上提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失去焦点. ...
随机推荐
- cf979d Kuro and GCD and XOR and SUM
set做法 正解是trie-- 主要是要学会 \(a\ \mathrm{xor}\ b \leq a+b\) 这种操作 #include <iostream> #include <c ...
- C#定时器,定时做什么事情
http://www.cnblogs.com/bobositlife/archive/2015/09/29/aspnet-mvc-csharp-quartz-net-timer-task-schedu ...
- 【LeetCode】Longest Substring Without Repeating Characters(无重复字符的最长子串)
这道题是LeetCode里的第3道题. 题目描述: 给定一个字符串,请你找出其中不含有重复字符的 最长子串 的长度. 示例 1: 输入: "abcabcbb" 输出: 3 解释: ...
- [oldboy-django][2深入django]FBV + CBV + 装饰器
FBV django CBV & FBV - FBV function basic view a. urls 设置 urls(r'^test.html$', views.test) b. vi ...
- Struts2中 ValueStack、ActionContext、ServletContext、request、session等 表格解析
变量 从ActionContext中获得 生命周期 用Ongl来读取值 使用ServletConfigInterceptor来注入 ActionContext类 静态方法ActionContext. ...
- Git详解之二 Git基础 转
http://www.open-open.com/lib/view/open1328069733264.html Git 基础 读完本章你就能上手使用 Git 了.本章将介绍几个最基本的,也是最常用的 ...
- post方式的数据抓取
public static String sendPost(String url, String param) { PrintWriter out = null; Buff ...
- 获取浏览器的homepage
主要知识点:跨进程访问数据 首先修改浏览器源码:BrowserSettings.java private static String getSDMCDefaultSharedPreferencesNa ...
- 背景.jpg
- 调用已发布的WebService
WebService服务演示 登录http://www.webxml.com.cn