• 键盘弹出后上提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);
                
            }
        }
        
        
    }

  • 相关阅读:
    Stereo Matching文献笔记之(一):《Cross-Scale Cost Aggregation for Stereo Matching》读后感~
    机器视觉之 ICP算法和RANSAC算法
    基于语义约束与 Graph Cuts 的稠密三维场景 重建
    RANSAC算法详解
    三维重建技术在无人机方面的应用如何?三维重建未来的学术前景如何?
    尺度空间(Scale space)理论
    网速调控、带宽限制原理探究
    Cisco交换机IOS升级
    Nmap
    vi实用命令集
  • 原文地址:https://www.cnblogs.com/lisa090818/p/3230494.html
Copyright © 2020-2023  润新知