zoukankan      html  css  js  c++  java
  • 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];
    }
  • 相关阅读:
    STL整理之map
    链表及数组模拟链表
    树链剖分详解
    Luogu P3879 【[TJOI2010]阅读理解】
    Luogu P2727 【01串 Stringsobits】
    CF1200D 【White Lines】
    Luogu P4945 【最后的战役】
    Luogu P4944 【PION贪吃蛇】
    Luogu P2426 【删数】
    P2163 【[SHOI2007]园丁的烦恼】
  • 原文地址:https://www.cnblogs.com/chebaodaren/p/4615718.html
Copyright © 2011-2022 走看看