代码部分
@interface LoginViewController ()
@property (strong,nonatomic)UITextField *nameTextField;
@property (strong,nonatomic)UITextField *pwdTextField;
@property (strong,nonatomic)UIButton *button;
@end
@implementation LoginViewController
- (void)viewDidLoad {
[superviewDidLoad];
[self.viewsetBackgroundColor:[UIColorwhiteColor]];
CGSize size = [UIScreenmainScreen].bounds.size;
CGFloat w = size.width -100;
CGFloat h = 40;
CGFloat x = (size.width - w) /2 - size.width;
CGFloat y = 100;
self.nameTextField = [selfgetTextField:CGRectMake(x, y, w, h)placeholder:@"请输入登录名"];
y = CGRectGetMaxY(self.nameTextField.frame) +20;
self.pwdTextField = [selfgetTextField:CGRectMake(x, y, w, h)placeholder:@"请输入登录密码"];
w = 200;
x = (size.width - w) / 2;
y = CGRectGetMaxY(self.pwdTextField.frame) +20 + size.height;
self.button = [selfgetButton:CGRectMake(x, y, w, h)];
//主要部分
[UIViewanimateWithDuration:1.0delay:0options:UIViewAnimationOptionCurveLinearanimations:^{
CGRect frame1 = self.nameTextField.frame;
frame1.origin.x += size.width;
[self.nameTextFieldsetFrame:frame1];
[UIViewanimateWithDuration:1.0delay:1.0options:UIViewAnimationOptionCurveLinearanimations:^{
CGRect frame2 = self.pwdTextField.frame;
frame2.origin.x += size.width;
[self.pwdTextFieldsetFrame:frame2];
} completion:^(BOOL finished) {
[UIViewanimateWithDuration:1.0delay:0usingSpringWithDamping:0.8initialSpringVelocity:0options:UIViewAnimationOptionCurveLinearanimations:^{
CGRect frame = self.button.frame;
frame.origin.y -= size.height;
self.button.frame = frame;
} completion:nil];
}];
} completion:^(BOOL finished) {
}];
}
-(UIButton *)getButton:(CGRect)frame
{
UIButton *button = [UIButtonbuttonWithType:UIButtonTypeCustom];
[button setBackgroundColor:[UIColorredColor]];
[button setTitle:@"Login"forState:UIControlStateNormal];
[button setFrame:frame];
[button.layer setCornerRadius:10];
[self.viewaddSubview:button];
return button;
}
-(UITextField *)getTextField:(CGRect)frame placeholder:(NSString *)placeholder
{
UITextField *textField = [[UITextFieldalloc]initWithFrame:frame];
[textField setPlaceholder:placeholder];
[textField.layersetCornerRadius:10];
[textField.layer setBorderWidth:1.0];
[textField.layersetBorderColor:[UIColorlightGrayColor].CGColor];
[textField setTextAlignment:NSTextAlignmentCenter];
[self.viewaddSubview:textField];
return textField;
}