整个画面上移,使键盘不挡住画面,去除键盘

来源:互联网 发布:扁平化java框架 编辑:程序博客网 时间:2024/03/29 19:15

1.UIScrollView *view1;

UITextField *name;

2.添加UITextFieldDelegate

3.-(BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
    [self.view setCenter:CGPointMake(400,100 )];
//    NSTimeInterval animationDuration=0.30f;
//    [UIView beginAnimations:@"ResizeForKeyboard" context:nil];
//    [UIView setAnimationDuration:animationDuration];
//    float width=self.view.frame.size.width;
//    float height=self.view.frame.size.height;
//    CGRect rect=CGRectMake(0.0f,-80,width,height);//上移80个单位,按实际情况设置
//    self.view.frame=rect;
//    [UIView commitAnimations];
    NSLog(@"   begin editing ");
    return YES;
}


-(void)textFieldDidEndEditing:(UITextField *)textField
{
    [self.view setCenter:CGPointMake(400, 0)];

    NSLog(@"   begin editing ");
}

4.设置name.delegate = self;



//去除键盘

-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{
    [oldPwdTxt resignFirstResponder];
    [newPwdTxt resignFirstResponder];
    [confirmNewPwdTxt resignFirstResponder];
}

原创粉丝点击