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. 强命名实用程序(SN.exe)

    不要在普通的命令行窗口中编译,请先打开C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Microsoft Visual Studio 2010 ...

  2. jmeter全局变量配置:将token运用到全局(跨线程组使用变量)

    请注意元器件的执行顺序: 请将提取token的配置原件放在设置全局变量的配置元器件前面(本来是一个超级马虎的人,真是俗称“方脑壳”啊) 1.获取登录后的token(提取可以用json path Ext ...

  3. PAT——乙级1016

    乙级PAT的1016 乙级的题相对比较简单,我也是主要联系写代码的格式,而不是联系算法. 1016 部分A+B (15 point(s)) 正整数 A 的“D​A​​(为 1 位整数)部分”定义为由  ...

  4. ubuntu 下openoffice安装

    openoffice官网建议的安装步骤:http://www.openoffice.org/download/index.html 前提条件 如果你希望Java集成,你要确保你有安装最新的JRE.它的 ...

  5. AngularJs 特性 之 指令系统

    <!DOCTYPE html> <html ng-app="myApp"> <head> <meta charset="utf- ...

  6. Log4j官方文档翻译(七、日志格式化)

    apache log4j提供各种layout对象,然后根据自己指定的layouts对象转化日志信息.通常来说都是应用量身定制layout对象转换信息格式. 所有的layout对象从Appender对象 ...

  7. BZOJ 1877:[SDOI2009]晨跑(最小费用最大流)

    晨跑DescriptionElaxia最近迷恋上了空手道,他为自己设定了一套健身计划,比如俯卧撑.仰卧起坐等 等,不过到目前为止,他坚持下来的只有晨跑. 现在给出一张学校附近的地图,这张地图中包含N个 ...

  8. 【Luogu】P2488工作安排(费用流)

    题目链接 这题……费用流即可……(哇啊要被打死辣) 然而我printf("%d")爆零四次 好的心如死灰 #include<cstdio> #include<cs ...

  9. MpLab设置编译文件输出路径

    MpLab设置编译文件输出路径

  10. CSU 1809 Parenthesis(RMQ-ST+思考)

    1809: Parenthesis Submit Description Bobo has a balanced parenthesis sequence P=p1 p2…pn of length n ...