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

注册监听键盘事件的通知

时间:2015-05-13 19:43:47      阅读:144      评论:0      收藏:0      [点我收藏+]

标签:

注册监听键盘事件的通知
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardShow:) name:UIKeyboardDidShowNotification object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardHide:) name:UIKeyboardDidHideNotification object:nil];

 

 

 

 在键盘将要出现和隐藏的回调中

- (void)keyboardWillShows:(NSNotification *)notif

{

    CGRect frame = [[notif.userInfo objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue];

 

    CGFloat  offset= -frame.size.height;

 

    [UIView animateWithDuration:0.3 animations:^{

        CGRect  rect  =self.frame;

       

        rect.origin.y=offset;

       

        self.frame=rect;

       

    }];

 

}

 

 

- (void)keyboardWillHides:(NSNotification *)notif

{

 

   

    [UIView animateWithDuration:0.3 animations:^{

        CGRect  rect  =self.frame;

       

        rect.origin.y=0;

       

        self.frame=rect;

        

    }];

 

注册监听键盘事件的通知

标签:

原文地址:http://www.cnblogs.com/woaixixi/p/4501250.html

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