zoukankan      html  css  js  c++  java
  • 监听键盘弹出 隐藏

    - (void)viewDidLoad {
        [super viewDidLoad];

        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
    }

    //隐藏键盘

    -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
    {
        [self.view endEditing:YES];
    }

    - (void)keyboardWillShow:(NSNotification *)notification {
        
        //改变window的背景颜色
        self.view.window.backgroundColor = self.view.backgroundColor;
        
        //  键盘退出的frame
        CGRect frame = [notification.userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue];
        
        //键盘实时y
        CGFloat keyY = frame.origin.y;
        

        if (_nextBtny <= keyY-LTloginInset ) {
            
            return;
        }
        
        CGFloat screenh = keyY-_nextBtny-LTloginInset;
        
        //动画时间
        CGFloat keyDuration = [notification.userInfo[UIKeyboardAnimationDurationUserInfoKey] floatValue];
        
            //执行动画
        [UIView animateWithDuration:keyDuration animations:^{
            self.view.transform = CGAffineTransformMakeTranslation(0,screenh );
        }];
    }


    - (void)keyboardWillHide:(NSNotification *)notification {
        
        //动画时间
        CGFloat keyDuration = [notification.userInfo[UIKeyboardAnimationDurationUserInfoKey] floatValue];
        
        //执行动画
        [UIView animateWithDuration:keyDuration animations:^{
            self.view.transform = CGAffineTransformMakeTranslation(0,0);
        }];

    }

    - (void)dealloc
    {
        
        [[NSNotificationCenter defaultCenter] removeObserver:self name:nil object:nil];
        
    }

  • 相关阅读:
    day1
    day0
    Scala编程快速入门系列(二)
    Scala编程快速入门系列(一)
    awk使用方法与案例介绍
    快速掌握Shell编程
    yum源配置的三种方法
    部署Kettle做ETL开发并使用Crontab制作调度系统
    大数据平台Hive数据迁移至阿里云ODPS平台流程与问题记录
    RDD概念、特性、缓存策略与容错
  • 原文地址:https://www.cnblogs.com/guangleijia/p/4759748.html
Copyright © 2011-2022 走看看