zoukankan      html  css  js  c++  java
  • 处理键盘弹出

    //======== 监听键盘的弹出事件 ========
    
        [[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];
    
    }
  • 相关阅读:
    NSDate 与NSString的互相转换
    NSArray 基础
    IOS 使用自定义字体
    页面跳转添加动画
    Builder 模式
    树的子结构
    Singleton 模式
    合并两个排序的链表(递归算法)
    合并两个排序的链表(非递归)
    反转链表
  • 原文地址:https://www.cnblogs.com/songxing10000/p/4518259.html
Copyright © 2011-2022 走看看