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

Keyboard 视图随键盘升高降低

时间:2014-12-05 19:24:14      阅读:169      评论:0      收藏:0      [点我收藏+]

标签:keyboard 键盘 升高 降低 升降

 (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 视图随键盘升高降低

标签:keyboard 键盘 升高 降低 升降

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

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