• 回缩键盘


    一、键值监听

       [[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];

        

    }

  • 相关阅读:
    C# SocketAsyncEventArgs Server
    C# Socket 入门5 UPD 结构体 与 C++ 通信
    如何取得 Func 对象 字段
    动态调用对象的属性和方法——性能和灵活性兼备的方法
    C# 读写锁 ReaderWriteLock
    C# IP多播
    C# 广播通信
    程序员那点儿事
    wince上数据库:sqlce和sqlite
    evc vc字符串转换处理
  • 原文地址:https://www.cnblogs.com/momosmile/p/5035485.html
Copyright © 2020-2023  润新知