登录界面动画



代码部分

@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;

}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值