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

键盘上升下降

时间:2017-06-26 12:47:06      阅读:164      评论:0      收藏:0      [点我收藏+]

标签:ima   key   frame   duration   userinfo   val   void   user   UI   

//当键盘出现或改变时调用

- (void)keyboardWillShow:(NSNotification *)aNotification

{

    NSDictionary *userInfo = [aNotification userInfo];

    NSValue *aValue = [userInfo objectForKey:UIKeyboardFrameEndUserInfoKey];

    CGRect keyboardRect = [aValue CGRectValue];

    CGFloat height = keyboardRect.size.height;

    CGFloat offset = CGRectGetMaxY(self.urlInput.frame) + 10 - (CGRectGetMaxY(self.view.bounds) - height);

    

    NSNumber *durationNum = [userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey];

    CGFloat duration = [durationNum floatValue];

    

    if (offset > 0)

    {

        [UIView animateWithDuration:duration animations:^{

            self.view.frame = CGRectMake(0,-offset, CGRectGetWidth(self.view.frame), CGRectGetHeight(self.view.frame));

        }];

    }

}

 

//当键退出时调用

- (void)keyboardWillHide:(NSNotification *)aNotification

{

    NSDictionary *userInfo = [aNotification userInfo];

    NSNumber *durationNum = [userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey];

    CGFloat duration = [durationNum floatValue];

    

    [UIView animateWithDuration:duration animations:^{

        self.view.frame = CGRectMake(0, 0, CGRectGetWidth(self.view.frame), CGRectGetHeight(self.view.frame));

    }];

}

 

键盘上升下降

标签:ima   key   frame   duration   userinfo   val   void   user   UI   

原文地址:http://www.cnblogs.com/danMing-love/p/7079728.html

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