• 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;
        }];
    }
  • 相关阅读:
    Windows命令处理进程
    Linux 文件权限管理
    Linux 用户与用户组管理
    Linux 文件类型及操作
    快速了解必要的网络知识
    SSH免密码登录
    用SSH访问内网主机的方法
    MongoDB与PostgresQL无责任初步测试
    SpringMVC的Action在同一时间里只允许同一个浏览器的单次进入?
    Netty5使用自签证书实现SSL安全连接
  • 原文地址:https://www.cnblogs.com/lihaibo-Leao/p/3139833.html
Copyright © 2020-2023  润新知