首页 > 其他 > 详细

回缩键盘

时间:2015-12-10 13:01:03      阅读:164      评论:0      收藏:0      [点我收藏+]

一、键值监听

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

    

}

回缩键盘

原文:http://www.cnblogs.com/momosmile/p/5035485.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!