码迷,mamicode.com
首页 > 移动开发 > 详细

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

时间:2016-06-08 18:37:15      阅读:191      评论:0      收藏:0      [点我收藏+]

标签:

首先实现 设置代理,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];
}

  

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

标签:

原文地址:http://www.cnblogs.com/oldk/p/5570731.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!