iOS中页面上移(要加委托UITextField/ViewDelegate)
2013-08-19 16:39
288 查看
在.h中
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;
}
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;
}
相关文章推荐
- IOS UITableView中UITextField 弹出键盘时,界面上移
- Bug: iOS用xib自定义view,UITextField的delegate没有调用
- IOS delegate 委托 使用 两个View之间传数据
- ios ViewController 页面跳转
- iOS开发中ViewController的页面跳转和弹出模态
- ios中关于delegate(委托)的使用心得
- IOS 在AppDelegate 页面中push到另一个页面
- iOS 7:用代码解决视图控制器的View整体上移问题
- [转]IOS Segment页面之间view的切换
- iOS页面间传值的方式(Delegate/NSNotification/Block/NSUserDefault
- iOS设计模式——委托(delegate)
- IOS开发之UIScrollViewDelegate详解
- 【委托】 IOS开发使用委托delegate在不同窗口之间传递数据
- iOS页面间传值的方式(Delegate/NSNotification/Block/NSUserDefault)
- iOS页面间传值的方式(Delegate/NSNotification/Block/NSUserDefault/单例)
- iOS中delegate(委托)的使用
- iOS webview缩小页面内容
- ios关于view-viewcontroller页面之间的跳转的方法
- iOS 从AppDelegate中跳转指定页面
- iOS页面间传值的方式(Delegate/NSNotification/Block/NSUserDefault/单例)