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);
                
            }
        }
        
        
    }

  • 相关阅读:
    django Highcharts制作图表--显示CPU使用率
    django--ajax的使用,应用
    Selenium&Pytesseract模拟登录+验证码识别
    django Highcharts制作图表--显示CPU使用率
    django--ajax的使用,应用
    斗鱼直播招聘测试总监
    腾讯自动化测试的AI智能
    转载Linq中GroupBy方法的使用总结
    转载.NET 4.0中的泛型的协变和逆变
    转载c#泛型 类型参数的约束(c#编程指南)
  • 原文地址:https://www.cnblogs.com/lisa090818/p/3230494.html
Copyright © 2011-2022 走看看