首页 > 移动平台 > 详细

iOS开发UI篇----UI高级之键盘通知

时间:2015-10-21 00:01:41      阅读:623      评论:0      收藏:0      [点我收藏+]

/*

      1.监听键盘通知 UIKeyboardWillChangeFrameNotification

      2.实现监听通知的方法

      3.调整控制器View的位置

      4.当控制器销毁的时候移除通知

     */

//监听键盘通知的方法

/*

 UIKeyboardAnimationCurveUserInfoKey = 7;  键盘弹出时候,执行动画的节奏

 UIKeyboardAnimationDurationUserInfoKey = "0.25"; 键盘动画执行的时间

 UIKeyboardBoundsUserInfoKey = "NSRect: {{0, 0}, {375, 258}}";  键盘大小

 UIKeyboardCenterBeginUserInfoKey = "NSPoint: {187.5, 796}";  键盘开始的时候中心点位置

 UIKeyboardCenterEndUserInfoKey = "NSPoint: {187.5, 538}";    键盘结束的时候中心点位置

 UIKeyboardFrameBeginUserInfoKey = "NSRect: {{0, 667}, {375, 258}}"; 键盘开始时候的frame

 UIKeyboardFrameEndUserInfoKey = "NSRect: {{0, 409}, {375, 258}}";   键盘结束的时候的frame

 

//  1.监听键盘通知 UIKeyboardWillChangeFrameNotification

    

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillChangeFrameNotification:) name:UIKeyboardWillChangeFrameNotification object:nil];

//2.实现监听通知的方法

- (void) keyboardWillChangeFrameNotification:(NSNotification *) notification

{

//    NSLog(@"%@",notification.userInfo);

    

// 键盘开始位置

    CGRect beginFrame  = [notification.userInfo[UIKeyboardFrameBeginUserInfoKey] CGRectValue];

// 键盘结束的位置

    CGRect endFrame = [notification.userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue];

//  取出控制器view的frame

    CGRect viewFrame = self.view.frame;

//  调整控制器view的y坐标

    viewFrame.origin.y += endFrame.origin.y - beginFrame.origin.y;

//  设置控制器的View的frame

    self.view.frame = viewFrame;

}

//移除监听者

-(void)dealloc{

    [[NSNotificationCenter defaultCenter]removeObserver:self];

}

 

    

 

iOS开发UI篇----UI高级之键盘通知

原文:http://www.cnblogs.com/DoNib-Coding/p/4896310.html

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