码迷,mamicode.com
首页 > 移动开发 > 详细

iOS 键盘的监听 调整view的位置

时间:2016-10-19 19:33:53      阅读:227      评论:0      收藏:0      [点我收藏+]

标签:

iOS在处理键盘的出现和消失时需要监听UIKeyboardWillChangeFrameNotifications/UIKeyboardDidHideNotifications

- (void)viewDidLoad
{
    [super viewDidLoad];

//添加监听 键盘消失
     [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardDown) name:UIKeyboardDidHideNotification object:nil];

//添加监听 键盘出现
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillChangeFrame:) name:UIKeyboardWillChangeFrameNotification object:nil];
}


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

//取出键盘动画的时间(根据userInfo的key-UIKeyboardAnimationDurationUserInfoKey)

    CGFloat duration = [noti.userInfo[UIKeyboardAnimationDurationUserInfoKey] floatValue];
    


 //取得键盘最后的frame(根据userInfo的key----UIKeyboardFrameEndUserInfoKey = "NSRect: {{0, 227}, {320, 253}}";)

    CGRect keyboardFrame = [noti.userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue];
  
//处理键盘出现的是页面的变化。。。。。。
}


- (void)keyboardDown
{
    //处理键盘消失是页面的变化 。。。。。。
}

 

iOS 键盘的监听 调整view的位置

标签:

原文地址:http://www.cnblogs.com/carlos-mm/p/5978278.html

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