IBOutlet UIView *_view2;
IBOutlet UITextField *nameText;
IBOutlet UITextField *mimaText;
在.m中
@interface EnterViewController ()
{
CGPoint Oldcenter;//原来界面的坐标
BOOL isShangyi; //因为有两个UITextField,所以要判断
}- (void)viewDidLoad
{
[super viewDidLoad];
Oldcenter = CGPointMake(_view2.center.x,_view2.center.y);
nameText.delegate = self; //委托
mimaText.delegate = self;
}
//页面上移
- (void)textFieldDidBeginEditing:(UITextField *)textField;
{
if(!isShangyi)
{
[UIView animateWithDuration:0.5 animations:^{
_view2.center = CGPointMake(_view2.center.x,_view2.center.y-150); //将原来中心点的纵坐标改了
}];
isShangyi = YES;
}
}
//完成编辑,页面回到初始位置
-(IBAction) finishBtnAction:(id)sender
{
[UIView animateWithDuration:0.5 animations:^{
_view2.center = CGPointMake(Oldcenter.x,Oldcenter.y);}]; //实现动画
isShangyi = NO;
}