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

第11月第31天 keyboardwillshow CGAffineTransformMakeTranslation

时间:2017-08-31 12:58:23      阅读:168      评论:0      收藏:0      [点我收藏+]

标签:div   style   span   add   orm   default   observer   elf   blog   

1.

- (void)dealloc
{
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}

- (void)registerNotification {
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(showKeyboard:) name:UIKeyboardWillShowNotification object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self  selector:@selector(hideKeyboard:) name:UIKeyboardWillHideNotification object:nil];
}

#pragma mark - keyboard
- (void)showKeyboard:(NSNotification *)noti {
    NSDictionary *info=[noti userInfo];
    
    NSTimeInterval duration = [info[UIKeyboardAnimationDurationUserInfoKey] doubleValue];
    UIViewAnimationOptions options = [info[UIKeyboardAnimationCurveUserInfoKey] unsignedIntegerValue] << 16;
    
    CGRect keyboardRect = [info[UIKeyboardFrameEndUserInfoKey] CGRectValue];
    CGFloat keyboardHeight = MIN(CGRectGetWidth(keyboardRect), CGRectGetHeight(keyboardRect));
    
    [UIView animateWithDuration:duration delay:0 options:options animations:^{
        CGFloat compareH = self.tableView.contentSize.height -(self.view.height - 45 - 64 - keyboardHeight);
        if (compareH >  0) {
            if (compareH < keyboardHeight) {
                self.tableView.transform = CGAffineTransformMakeTranslation(0, -compareH);
            } else {
                self.tableView.transform = CGAffineTransformMakeTranslation(0, -keyboardHeight);
            }
        }
        
        self.bottomView.transform = CGAffineTransformMakeTranslation(0, -keyboardHeight);
        
    } completion:nil];
}

- (void)hideKeyboard:(NSNotification *)noti {
    
    NSDictionary *info=[noti userInfo];
    
    NSTimeInterval duration = [info[UIKeyboardAnimationDurationUserInfoKey] doubleValue];
    UIViewAnimationOptions options = [info[UIKeyboardAnimationCurveUserInfoKey] unsignedIntegerValue] << 16;
    
    [UIView animateWithDuration:duration delay:0 options:options animations:^{
        
        self.tableView.transform = CGAffineTransformIdentity;
        self.bottomView.transform = CGAffineTransformIdentity;
        
    } completion:nil];
    
}

 

第11月第31天 keyboardwillshow CGAffineTransformMakeTranslation

标签:div   style   span   add   orm   default   observer   elf   blog   

原文地址:http://www.cnblogs.com/javastart/p/7457470.html

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