zoukankan      html  css  js  c++  java
  • ios开发 点击文本(TextField)输入的时候向上推以及输入之后恢复的动画

    1.添加委托UITextFieldDelegate

    2.

    -(BOOL)textFieldShouldReturn:(UITextField *)textField {
        [textField resignFirstResponder];
        return YES;
    }  //隐藏键盘
    - (void)textFieldDidBeginEditing:(UITextField *)textField {
        [self animateTextField: textField up: YES];
    }
    - (void)textFieldDidEndEditing:(UITextField *)textField {
        [self animateTextField: textField up: NO];
    }
    - (void) animateTextField: (UITextField*) textField up: (BOOL) up {
        const int movementDistance = 60; // tweak as needed
        const float movementDuration = 0.3f; // tweak as needed
        
        int movement = (up ? -movementDistance : movementDistance);
        
        [UIView beginAnimations: @"anim" context: nil];
        [UIView setAnimationBeginsFromCurrentState: YES];
        [UIView setAnimationDuration: movementDuration];
        self.view.frame = CGRectOffset(self.view.frame, 0, movement);
        [UIView commitAnimations];
    }
     [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyBoardWillShow:) name:UIKeyboardWillShowNotification object:nil];
        
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyBoardWillHide:) name:UIKeyboardWillHideNotification object:nil];
    
    
    #pragma mark - 键盘处理
    #pragma mark 键盘即将显示
    
    - (void)keyBoardWillShow:(NSNotification *)note{
        
        CGRect rect = [note.userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue];
        CGFloat ty = - rect.size.height;
        [UIView animateWithDuration:[note.userInfo[UIKeyboardAnimationDurationUserInfoKey] doubleValue] animations:^{
            self.view.transform = CGAffineTransformMakeTranslation(0, ty + kNavigationBarHeight);
        }];
        
    }
    
    #pragma mark 键盘即将退出
    
    - (void)keyBoardWillHide:(NSNotification *)note{
        
        [UIView animateWithDuration:[note.userInfo[UIKeyboardAnimationDurationUserInfoKey] doubleValue] animations:^{
            self.view.transform = CGAffineTransformIdentity;
        }];
    }
  • 相关阅读:
    动态增加数据库表字段
    Centos7 + Python3.6 + Django + virtualenv + gunicorn + supervisor 环境配置详解
    typeof关键字简介 -rtti
    c++ typeid获取类型名-rtti
    C++ 中dynamic_cast<>的使用方法小结 -判断类型-rtti
    Java 8 Lambda表达式探险
    Lambda表达式详解
    android:ToolBar详解(手把手教程)(转)
    linux numfmt 命令--转换数字
    android mk odex问题 push apk 不生效
  • 原文地址:https://www.cnblogs.com/lihaibo-Leao/p/3139833.html
Copyright © 2011-2022 走看看