zoukankan      html  css  js  c++  java
  • 回缩键盘

    一、键值监听

       [[NSNotificationCenter defaultCenter] addObserver:self

                                                 selector:@selector(keyboardWillShow:)

                                                     name:UIKeyboardWillShowNotification

                                                   object:nil];

        //增加监听,当键退出时收出消息

        [[NSNotificationCenter defaultCenter] addObserver:self

                                                 selector:@selector(keyboardWillHide:)

                                                     name:UIKeyboardWillHideNotification

                                                   object:nil];

    #pragma mark ------- Action

    - (void)keyboardWillShow:(NSNotification *)aNotification

    {

        //获取键盘的高度

        NSDictionary *userInfo = [aNotification userInfo];

        NSValue *aValue = [userInfo objectForKey:UIKeyboardFrameEndUserInfoKey];

        CGRect keyboardRect = [aValue CGRectValue];

        CGFloat keyHeight = keyboardRect.size.height;

        self.view.top=100-keyHeight;

        //    if ([_emailText isFirstResponder]) {

        //        if(kDeviceHeight<_emailText.bottom+keyHeight+64)

        //            self.view.top=64+(kDeviceHeight-_emailText.bottom-keyHeight-64);

        //    }

        

    }

    - (void)keyboardWillHide:(NSNotification *)aNotification

    {

        //获取键盘的高度

        self.view.top=64;

    }

    二、手势监听

     UITapGestureRecognizer *tap1 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(viewTapped:)];

        tap1.cancelsTouchesInView = NO;

        [self.view addGestureRecognizer:tap1];

    #pragma mark----点击空白处收起键盘

    -(void)viewTapped:(UITapGestureRecognizer*)tap1

    {

        

        [self.view endEditing:YES];

        

    }

  • 相关阅读:
    除去DataTable中的空行!
    通过cmd命令安装、卸载、启动和停止Windows Service(InstallUtil.exe)
    installshield学习笔记
    托管与非托管
    C#语言之“String.Split”的使用【转】
    C#语言之“中英文混合字符串对齐”的方法
    栈和堆的区别
    UNICODE与ANSI的区别
    C#多线程:深入了解线程同步lock,Monitor,Mutex,同步事件和等待句柄(中)
    java自定义注解
  • 原文地址:https://www.cnblogs.com/momosmile/p/5035485.html
Copyright © 2011-2022 走看看