zoukankan      html  css  js  c++  java
  • 状态键盘完美适应iOS中的键盘高度变化

    PS:明天上午,非常郁闷,有很多简单基础的问题搞得我有些迷茫,哎,代码几天不写就忘。目前又不当COO,还是得用心记代码哦!

        很久以前写了一篇文章,探讨如何《自适应iPhone的不同键盘高度》,明天得觉可以美完随跟:

        每日一道理
    成熟是一种明亮而不刺眼的光辉,一种圆润而不腻耳的音响,一种不需要对别人察颜观色的从容,一种终于停止了向周围申诉求告的大气,一种不理会哄闹的微笑,一种洗刷了偏激的淡漠,一种无须声张的厚实,一种并不陡峭的高度。
    #pragma mark - reg & unreg notification
    
    - (void)regNotification
    {
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillChangeFrame:) name:UIKeyboardWillChangeFrameNotification object:nil];
    }
    
    - (void)unregNotification
    {
        [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillChangeFrameNotification object:nil];
    }
    
    #pragma mark - notification handler
    
    - (void)keyboardWillChangeFrame:(NSNotification *)notification
    {
        NSDictionary *info = [notification userInfo];
        CGFloat duration = [[info objectForKey:UIKeyboardAnimationDurationUserInfoKey] floatValue];
        CGRect beginKeyboardRect = [[info objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue];
        CGRect endKeyboardRect = [[info objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue];
        
        CGFloat yOffset = endKeyboardRect.origin.y - beginKeyboardRect.origin.y;
        
        CGRect inputFieldRect = self.inputTextField.frame;
        CGRect moreBtnRect = self.moreInputTypeBtn.frame;
        
        inputFieldRect.origin.y += yOffset;
        moreBtnRect.origin.y += yOffset;
        
        [UIView animateWithDuration:duration animations:^{
            self.inputTextField.frame = inputFieldRect;
            self.moreInputTypeBtn.frame = moreBtnRect;
        }];
    }

        通过获得键盘消息的开始状态、束结状态,以及变更期周,可以计算出体具的Y偏移,从而在雷同时间里做雷同偏移量。

    文章结束给大家分享下程序员的一些笑话语录: Borland说我很有前途,Sun笑了;Sun说我很有钱,IBM笑了;IBM说我很专业,Sybase笑了;Sybase说我数据库很牛,Oracle笑了;Oracle说我是开放的,Linux笑了;Linux说我要打败Unix,微软笑了;微软说我的系统很稳定,我们都笑了。

  • 相关阅读:
    Djnago中缓存配置(redis配置案例)
    HDU-4717 The Moving Points 三分
    HDU-4716 A Computer Graphics Problem 水题
    HDU-2686 Matrix 多进程DP
    [转]手动开平方的简易方法
    [转]树链剖分
    HUOJ-10857 最大的面积 凸包+DP
    Bnuoj-29359 Deal with numbers 线段树
    HDU-4283 You Are the One 区间DP
    BNUOJ-26586 Simon the Spider 最小生成树+枚举
  • 原文地址:https://www.cnblogs.com/xinyuyuanm/p/3043192.html
Copyright © 2011-2022 走看看