zoukankan      html  css  js  c++  java
  • 键盘的监听 和 取消第一响应者

    一.监听键盘的弹出和退出(键盘的高度和弹出时间可用来做动画)

        // 监听键盘的通知

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

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

    /**

     *  键盘即将显示的时候调用

     */

    - (void)keyboardWillShow:(NSNotification *)note

    {

        // 1.取出键盘的frame

        CGRect keyboardF = [note.userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue];

        

        // 2.取出键盘弹出的时间

        CGFloat duration = [note.userInfo[UIKeyboardAnimationDurationUserInfoKey] doubleValue];

        

        // 3.执行动画

        [UIView animateWithDuration:duration animations:^{

            self.toolbar.transform = CGAffineTransformMakeTranslation(0, -keyboardF.size.height);

        }];

    }

    /**

     *  键盘即将退出的时候调用

     */

    - (void)keyboardWillHide:(NSNotification *)note

    {

        // 1.取出键盘弹出的时间

        CGFloat duration = [note.userInfo[UIKeyboardAnimationDurationUserInfoKey] doubleValue];

        

        // 2.执行动画

        [UIView animateWithDuration:duration animations:^{

            self.toolbar.transform = CGAffineTransformIdentity;

        }];

    }

    二、成为第一响应者和取消第一响应者

    1.取消第一响应者

        [self.view endEditing:YES];//view或view的子控件都取消第一响应者

        或[self.textView resignFirstResponder];//直接让控件取消第一响应者

    2.成为第一响应者

        [self.textView becomeFirstResponder];

  • 相关阅读:
    SQL Server 中的事务与事务隔离级别以及如何理解脏读, 未提交读,不可重复读和幻读产生的过程和原因
    微软BI 之SSIS 系列
    微软BI 之SSIS 系列
    微软BI 之SSIS 系列
    微软BI 之SSIS 系列
    微软BI 之SSIS 系列
    微软BI 之SSAS 系列
    微软BI 之SSRS 系列
    微软BI 之SSRS 系列
    配置 SQL Server Email 发送以及 Job 的 Notification通知功能
  • 原文地址:https://www.cnblogs.com/junhuawang/p/4610632.html
Copyright © 2011-2022 走看看