码迷,mamicode.com
首页 > 其他好文 > 详细

2016-02-22 监听键盘 隐藏bar

时间:2016-02-23 11:17:17      阅读:122      评论:0      收藏:0      [点我收藏+]

标签:

- (BOOL)prefersStatusBarHidden{

    return YES;

}   //隐藏bar

 

 2:让键盘消失

////    [_lastField resignFirstResponder];

//    [self.view endEditing:YES];//gzz0223

//    

//    //gzz0223 键盘消失

//    NSArray *subviews = [self.view subviews];

//    for (id objInput in subviews) {

//        if ([objInput isKindOfClass:[UITextField class]]) {

//            UITextField *theTextField = objInput;

//            if ([objInput isFirstResponder]) {

//                [theTextField resignFirstResponder];

//            }

//        }

//    }

        [[[UIApplication sharedApplication] keyWindow] endEditing:YES];

 

 

 

 //监听键盘出现

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

    //监听键盘消失

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

 

}

 

//键盘出现,chatView向上移动

- (void)keyboardWillShow:(NSNotification*)noti{

    //获取键盘的高度

    CGSize size = [noti.userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue].size;

    //屏幕宽高

    CGSize winSize = self.view.frame.size;

    //tableView的大小

    _tableView.frame = CGRectMake(0, 0, winSize.width, winSize.height - 40 - size.height);

    //chatView的位置

    _chatView.frame = CGRectMake(0, winSize.height - 40 - size.height, winSize.width, 40);

}

 

//键盘消失,将chatView恢复原位

- (void)keyboardWillHide:(NSNotification*)noti{

    //屏幕宽高

    CGSize winSize = self.view.frame.size;

    //tableView的大小恢复

    _tableView.frame = CGRectMake(0, 0, winSize.width, winSize.height - 40);

    //chatView的位置恢复

    _chatView.frame = CGRectMake(0, winSize.height - 40, winSize.width, 40);

}

2016-02-22 监听键盘 隐藏bar

标签:

原文地址:http://www.cnblogs.com/gzz2016/p/5208892.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!