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显示错误的更多相关文章

  1. 周记3——解决fixed属性在ios软键盘弹出后失效的bug

    这周在做空间(“类似”qq空间)项目.首页是好友发表的说说,可以针对每条说说进行评论,评论框吸附固定在屏幕底部.此时,Bug来了...在ios上,软键盘弹出后fixed属性失效了.后来发现,ios绝大 ...

  2. Ionic3学习笔记(九)关于 Android 端软键盘弹出后界面被压缩的问题

    本文为原创文章,转载请标明出处 今天做了一个如下图所示的页面. iOS 端毫无 bug,Android 端却出现了问题.当软键盘弹出后,Android 端的 tabs 移到了软键盘的上面,再仔细一看, ...

  3. KeyboardUtil【软键盘弹出后输入框上移一定的高度】

    版权声明:本文为HaiyuKing原创文章,转载请注明出处! 前言 演示获取软键盘高度并保存,然后根据输入框的原有位置是否被软键盘挡住了,如果被挡住了则将整体页面上移一定的高度,当软键盘隐藏的时候再下 ...

  4. RecyclerView上拉隐藏Toolbar,下拉显示

    RecyclerView下拉隐藏Toolbar,上拉显示效果图 先说个事:最近我准备做个开源的博客园android客户端!符合Google最新的material design设计风格的!不知道有没有小 ...

  5. dropload.js 上滑加载,下拉刷新

    https://github.com/ximan/dropload dropload a javascript implementation of pull to refresh and up to ...

  6. select框默认样式去除(ie中隐藏默认下拉图标)

    html代码 <select class="info-select"> <option selected="selected">1< ...

  7. Web 1三级联动 下拉框 2添加修改删除 弹框

    Web  三级联动 下拉框 using System; using System.Collections.Generic; using System.Linq; using System.Web; u ...

  8. 隐藏AutoCompleteTextView下拉框的滚动条

    最近做项目需要用到AutoCompleteTextView这个控件,而其下拉框的滚动条有点难看,于是想去掉.走了些弯路,终于弄通了. 首先先介绍一种不靠谱的方法:反射机制 为什么会有人想到用这个呢? ...

  9. 关于ListView中EditText在软键盘弹出后的焦点问题

    转自:http://www.cnblogs.com/haofei/p/3305030.html 在ListView中,每次弹出软键盘后就会重新调用getView()方法,导致EditText失去焦点. ...

随机推荐

  1. Event log c++ sample.

    1. Init regedit. bool InitLog( TCHAR *logName, TCHAR *sourceName, TCHAR *MessageDllName ) { // This ...

  2. 【Combination Sum II 】cpp

    题目: Given a collection of candidate numbers (C) and a target number (T), find all unique combination ...

  3. 浅谈我所见的CSS组织风格

    1.简单组织(见习级) projectName ├─css | └style.css 优点:简单,单一文件,适合一些简单项目. 缺点:过度集中,没有模块化,无法适应大型项目. 2.公共组织(见习级) ...

  4. Python+selenium(警告框处理)

    在Webdriver中处理JavaScript生成的alert.confirm.prompt,使用switch_to_alert()方法定位到alert.confirm.prompt,然后进行如下操作 ...

  5. 初学Linux 命令

    查看ip:ifconfig 切换用户:us root(root为用户名) 显示当前目录:pwd 列出当前目录下所有文件:ls 进入某个目录 :cd 创建一个文件夹:mkdir 创建多个目录(当没有该父 ...

  6. maven学习(十三)——eclipse整合maven插件

    一.安装Maven插件 下载下来的maven插件如下图所示:,插件存放的路径是:E:/MavenProject/Maven2EclipsePlugin

  7. ansible Failed to connect to the host via ssh: no such identity: /root/.ssh/id_rsa.bak

    中控机和远端主机配置完密钥后,在中控台上通过ansible检测联通性 ansible -i inventory.cfg all -m ping 10.1.1.1 | UNREACHABLE! => ...

  8. cf 853 D Michael and Charging Stations [dp]

    题面: 传送门 思路: 看到题目,第一思路是贪心,但是我很快就否决掉了(其实分类贪心也可以做) 然后就想,贪心不能解决的状态缺失,是否可以用dp来解决呢? 事实证明是可以的 我们设dp[i][j]表示 ...

  9. python 读取文件夹下的图片进行处理

    python的os模块中有一个listdir函数可以遍历读取文件夹下的文件. import os for filename in os.listdir(r"./file"): #l ...

  10. codevs 1380/HDU 1520 树形dp

    1380 没有上司的舞会 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 钻石 Diamond 题解 查看运行结果 回到问题 题目描述 Description Ural大学有N个职员 ...