zoukankan      html  css  js  c++  java
  • 键盘弹出后上提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);
                
            }
        }
        
        
    }

  • 相关阅读:
    python scapy的用法之ARP主机扫描和ARP欺骗
    Python字典取键、值对
    python字典添加元素和删除元素
    Python删除列表元素
    获取本机的IP地址和mac地址
    Python查找电话号码归属地、邮编、运营商信息等
    Python的字符串格式化,%与format
    Python基础笔记一之字符转化、复数、位运算、除法运算、floor和ceil取整,round函数四舍五入
    FAILED: SemanticException Unable to determine if hdfs://tmaster:8020/user/root/words.db/test_t2 is encrypted
    Pyspark读取csv文件
  • 原文地址:https://www.cnblogs.com/lisa090818/p/3230494.html
Copyright © 2011-2022 走看看