• 处理键盘弹出


    //======== 监听键盘的弹出事件 ========
    
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillChangeFrame:) name:UIKeyboardWillChangeFrameNotification object:nil];
    
    
    
    // 当键盘的位置大小发生改变时触发
    
    - (void)keyboardWillChangeFrame:(NSNotification *)note
    
    {
    
        // 1. 获取键盘当前的高度
    
        NSLog(@"%@", note.userInfo);
    
        CGFloat screenH = [UIScreen mainScreen].bounds.size.height;
    
        CGRect rect = [note.userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue];
    
        CGFloat keyboardY = rect.origin.y;
    
        CGFloat duration = [note.userInfo[UIKeyboardAnimationDurationUserInfoKey] doubleValue];
    
        
    
        /// 2.将当前ViewController的View整体向上平移一个"键盘的高度"
    
        [UIView animateWithDuration:duration animations:^{
    
            self.view.transform = CGAffineTransformMakeTranslation(0, keyboardY - screenH);
    
        }];
    
        
    
    }
    
     
    ///记得移除通知
    - (void)dealloc
    
    {
    
        [[NSNotificationCenter defaultCenter] removeObserver:self];
    
    }
  • 相关阅读:
    2001.3.9 每日总结
    2021.3.5
    2021.3.4每日总结
    2021.3.3每日总结
    每日总结2021.3.2
    2021.1.13
    2021.1.12
    PodPreset
    ingress-nginx安装
    RBAC
  • 原文地址:https://www.cnblogs.com/songxing10000/p/4518259.html
Copyright © 2020-2023  润新知