• ios 含有textfield的viewcontroller随键盘弹起而改变位置


    首先实现 设置代理,self.textfield.delegate = self;

    具体实现代码:
    -(void)textFieldDidBeginEditing:(UITextField *)textField{
        NSTimeInterval animationDuration = 0.30f;
        [UIView beginAnimations:@"ResizeForKeyboard" context:nil];
        [UIView setAnimationDuration:animationDuration];
        if ([UIScreen mainScreen].bounds.size.width>320) {
            //将视图的Y坐标向上移动,以使下面腾出地方用于软键盘的显示
            self.view.frame = CGRectMake(0.0f, -200.0f, self.view.frame.size.width, self.view.frame.size.height);//64-216
            [UIView commitAnimations];
        }
        else{
            self.view.frame = CGRectMake(0.0f, -170.0f, self.view.frame.size.width, self.view.frame.size.height);
            [UIView commitAnimations];
        }
    }
    
    -(void)textFieldDidEndEditing:(UITextField *)textField{
        //滑动效果
        NSTimeInterval animationDuration = 0.30f;
        [UIView beginAnimations:@"ResizeForKeyboard" context:nil];
        [UIView setAnimationDuration:animationDuration];
        
        //恢复屏幕
        self.view.frame = CGRectMake(0.0f, 0.0f, self.view.frame.size.width, self.view.frame.size.height);//64-216
        
        [UIView commitAnimations];
    }
    

      

  • 相关阅读:
    redis分布式锁
    pod资源清单
    zookeeper
    [置顶]【WP】 Writeup for SJTU-CTF ,被同级大佬和学长联合虐爆
    魔术师猜数【更优解】
    数学基础之线代
    向量是什么?
    矩阵与线性变换
    线性组合、张成的空间、基
    线性代数的本质
  • 原文地址:https://www.cnblogs.com/oldk/p/5570731.html
Copyright © 2020-2023  润新知