• 状态键盘完美适应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,微软笑了;微软说我的系统很稳定,我们都笑了。

  • 相关阅读:
    【大数据】Hadoop常用启动命令
    Codeforces Round #695 (Div. 2)
    Codeforces Round #668 (Div. 2)
    Codeforces Round #666 (Div. 2)
    Educational Codeforces Round 94 (Rated for Div. 2)
    Sum Queries? CodeForces
    New Year and Old Subsequence CodeForces
    Gym
    huntian oy HDU
    The Boss on Mars HDU
  • 原文地址:https://www.cnblogs.com/xinyuyuanm/p/3043192.html
Copyright © 2020-2023  润新知