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

ios 弹出键盘 视图向上平移

时间:2016-01-18 19:05:26      阅读:219      评论:0      收藏:0      [点我收藏+]

标签:


    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(keyboardwillAppear:) name:UIKeyboardWillShowNotification object:nil];
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(keyboardWillDisappear:) name:UIKeyboardWillHideNotification object:nil];
    
}

-(CGFloat)keyboardEndingFrameHeight:(NSDictionary *)userInfo//计算键盘的高度
{
    CGRect keyboardEndingUncorrectedFrame = [[userInfo objectForKey:UIKeyboardFrameEndUserInfoKey]CGRectValue];
    CGRect keyboardEndingFrame = [self.view convertRect:keyboardEndingUncorrectedFrame fromView:nil];
    return keyboardEndingFrame.size.height;
}

-(void)keyboardwillAppear:(NSNotification *)notification
{
    CGRect currentFrame = self.view.frame;
    NSLog(@"currentFrame.origin.y: %f",currentFrame.origin.y);
    if (currentFrame.origin.y!=0.00) {
        return;
    }
//    CGFloat change = [self keyboardEndingFrameHeight:[notification userInfo]];
    currentFrame.origin.y = -60 ;
    self.view.frame = currentFrame;
}

-(void)keyboardWillDisappear:(NSNotification *)notification
{
    CGRect currentFrame = self.view.frame;
//    CGFloat change = [self keyboardEndingFrameHeight:[notification userInfo]];
    currentFrame.origin.y = 0.0;//currentFrame.origin.y + change ;
    self.view.frame = currentFrame;
}

ios 弹出键盘 视图向上平移

标签:

原文地址:http://www.cnblogs.com/frounk/p/5140126.html

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