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. error LNK2001: unresolved external symbol ___CxxFrameHandler3

    Q:  VS2005编译的静态库, 在vc++6.0中连接出现错误 error LNK2001: unresolved external symbol ___CxxFrameHandler3 A:   ...

  2. Hotspot GC实现原理

    GC扫描 可达性分析的GC Roots主要是全局性引用或在Stack Frame中 ,现在的应用仅仅方法区往往就有几百兆,这样要这个检查这里面的引用,就必然会消耗很多时间,效率很低. 分析工作在一个保 ...

  3. 高亮T4模板

    http://t4-editor.tangible-engineering.com/Download_T4Editor_Plus_ModelingTools.html

  4. Windows网络编程笔记2

    这一次看看重定向器和如何使用Netbios函数获取本机mac地址 5.获取Mac地址 利用NCBASTAT命令实现,适配器状态命令会返回一个 ADAPTER_STATUS结构,紧接着是大量 NAME_ ...

  5. 使用 NPC,NPCManager 在 XNA 中创建 NPC(十九)

    平方已经开发了一些 Windows Phone 上的一些游戏,算不上什么技术大牛.在这里分享一下经验,仅为了和各位朋友交流经验.平方会逐步将自己编写的类上传到托管项目中,没有什么好名字,就叫 WPXN ...

  6. rpm包管理 命令

    rpm -ivh package.rpmrpm -ivh --force  package_name.rpm # ...conflict with...rpm -ivh --nodeps packag ...

  7. idea调试查看mybitis发送的语句(引用)

    MyBatis 的配置文件 Configuration 中有相关属性,设属性即可,不用再放一个 log4j.properties 文件. <configuration> <setti ...

  8. web项目中各种路径的获取(复制,为以后好找资源)

    web项目中各种路径的获取 1.可以在servlet的init方法里 String path = getServletContext().getRealPath("/"); 这将获 ...

  9. ValueStack、ActionContext

    笔者不知道该用哪个词来形容ValueStack.ActionContext等可以在Struts2中用来存放数据的类.这些类使用的范围不同,得到的方法也不同,下面就来一一介绍. 1. ValueStac ...

  10. mysql event 学习

    mysql 通过事件可以实现定时任务 : 1. 检查你的MYSQL是否开了这个功能 show variables like "%scheduler" //注意 最后是er 2.   ...