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;
        }];
    }
  • 相关阅读:
    Ajax调用WCF报405错误
    字符串转json方法
    正则取括号里面的内容
    string[] 转int[] 的方法
    C# 中结构与类的区别
    通用的权限模块是如何设计的?
    .net打包自动安装数据库!
    VS.net 2005快捷键一览表
    Windows Forms DataGridView 中合并单元格
    VS2005 制作安装程序
  • 原文地址:https://www.cnblogs.com/lihaibo-Leao/p/3139833.html
Copyright © 2011-2022 走看看