zoukankan      html  css  js  c++  java
  • iOS Dev (54) 键盘弹出后收起时View随之移动

    版权声明:本文为 CSDN 博主 大锐哥(ID 为 prevention)原创文章。未经博主同意不得转载。 https://blog.csdn.net/prevention/article/details/32324617

    iOS Dev (54) 键盘弹出后收起时View随之移动

    -

    加入监听

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

    移除监听

    [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillShowNotification object:nil];
    [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillHideNotification object:nil];
    

    事件处理函数

    - (void) changeContentViewPosition:(NSNotification *)notification{
    
        NSDictionary *userInfo = [notification userInfo];
        NSValue *value = [userInfo objectForKey:UIKeyboardFrameEndUserInfoKey];
        CGFloat keyBoardEndY = value.CGRectValue.origin.y;
    
        NSNumber *duration = [userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey];
        NSNumber *curve = [userInfo objectForKey:UIKeyboardAnimationCurveUserInfoKey];
    
        [UIView animateWithDuration:duration.doubleValue animations:^{
            [UIView setAnimationBeginsFromCurrentState:YES];
            [UIView setAnimationCurve:[curve intValue]];
            self.view.center = CGPointMake(self.view.center.x, keyBoardEndY - STATUS_BAR_HEIGHT - self.view.bounds.size.height/2.0);
        }];
    }
    

    Reference

    • http://www.cnblogs.com/programmer-blog/p/3265110.html
  • 相关阅读:
    python dataformat.py通用数据格式转化脚本
    python ftp操作脚本&常用函数
    函数的作用域
    阶段规划
    Linux 远程登录Windows图形界面
    php常用的几个算法
    书目列表【当前&后续】
    提高工作效率的工具[分享]
    浏览器的调试软件
    Linux回收站[改写rm防止误删文件无法恢复]
  • 原文地址:https://www.cnblogs.com/mqxnongmin/p/10873544.html
Copyright © 2011-2022 走看看