• iOS 获取键盘下落速度


    使自己创建的View根据键盘的显示和下落而改变frame,这需要使用iOS的通知机制,首先需要在通知中心注册

    1     [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWasShown:) name:UIKeyboardWillShowNotification object:nil];
    2     
    3     [[NSNotificationCenter defaultCenter]  addObserver:self selector:@selector(keyboardWasHidden:) name:UIKeyboardWillHideNotification object:nil];

    下面是绑定的方法代码

    - (void) keyboardWasShown:(NSNotification *) notif
    {
            _tableView.frame=CGRectMake(0, -110, MAIN_WIDTH, MAIN_HRIGHT);
    }
    
    - (void) keyboardWasHidden:(NSNotification *) notif
    {
        _tableView.frame=CGRectMake(0, 0, MAIN_WIDTH, MAIN_HRIGHT);
    }

    上面的代码是没有写动画效果的,但是却可以实现和键盘同速率的改变frame,这是一个很棒的功能

    如果不放心的话,可以自己手动写动画效果,下面是代码

    - (void) keyboardWasShown:(NSNotification *) notif
    {
        [UIView beginAnimations:nil context:nil];
        [UIView setAnimationDuration:[[notif.userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey] floatValue]];
        [UIView setAnimationCurve:[[notif.userInfo objectForKey:UIKeyboardAnimationCurveUserInfoKey] integerValue]];
        _tableView.frame=CGRectMake(0, -110, MAIN_WIDTH, MAIN_HRIGHT);
        [UIView commitAnimations];
    }
  • 相关阅读:
    BZOJ1106[POI2007]立方体大作战tet
    BZOJ4407 于神之怒加强版
    BZOJ1103: [POI2007]大都市meg
    BZOJ3170: [Tjoi2013]松鼠聚会
    Luogu 2912 [USACO08OCT]牧场散步Pasture Walking
    BZOJ1251 序列终结者- splay
    BZOJ1699: [Usaco2007 Jan]Balanced Lineup排队
    BZOJ 1005[HNOI2008]明明的烦恼
    二叉树
    [CODEVS1130]数字反转
  • 原文地址:https://www.cnblogs.com/chebaodaren/p/4615718.html
Copyright © 2020-2023  润新知