首页 > 其他 > 详细

Keyboard 视图随键盘升高降低

时间:2014-12-05 19:22:04      阅读:238      评论:0      收藏:0      [点我收藏+]

 (void)viewWillAppear:(BOOL)animated

{

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

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

}


- (void)keyboardWillShow:(NSNotification *)noti

{

    //得到keyboard size

    CGRect keyboardBounds;

    [[noti.userInfo valueForKeyPath:UIKeyboardFrameEndUserInfoKey]getValue:&keyboardBounds];

    

    CGRect frame ;

    if (version<7.0) {

        frame = CGRectMake(0, 0, mainHeight, mainHeight-20);;

    }else{

        frame = CGRectMake(0, 0, mainHeight, mainHeight);;

    }

    

    [UIView beginAnimations:nil context:NULL];

    [UIView setAnimationBeginsFromCurrentState:YES];

    [UIView setAnimationDuration:0.3f];

    

    if (mainHeight<500) {

        frame.origin.y -= 110;

    } else {

       frame.origin.y -= 25;

    }

    

    

    _backView.frame = frame;

    [UIView commitAnimations];

}


- (void)keyboardWillHide:(NSNotification *)noti

{

    //得到keyboard size

    CGRect keyboardBounds;

    [[noti.userInfo valueForKeyPath:UIKeyboardFrameEndUserInfoKey]getValue:&keyboardBounds];

    

    CGRect frame ;

    if (version<7.0) {

        frame = CGRectMake(0, 0, mainHeight, mainHeight-20);;

    }else{

        frame = CGRectMake(0, 0, mainHeight, mainHeight);;

    }

    

    [UIView beginAnimations:nil context:NULL];

    [UIView setAnimationBeginsFromCurrentState:YES];

    [UIView setAnimationDuration:0.3f];

    

    _backView.frame = frame;

    

    

    [UIView commitAnimations];

}

Keyboard 视图随键盘升高降低

原文:http://blog.csdn.net/zh_2608/article/details/41750655

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