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];
    }
  • 相关阅读:
    python--io多路复用之select实现
    python--基于socket网络编程
    python--面向对象编程之学生选课系统练习
    python--异常处理
    python--面向对象之三个特性:封装、继承、多态
    python--反射机制
    python--生成器和迭代器
    elasticsearch 创建索引
    elasticsearch 集群搭建
    linux 安装Mosquitto
  • 原文地址:https://www.cnblogs.com/chebaodaren/p/4615718.html
Copyright © 2011-2022 走看看