登錄界面動畫



代碼部分

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

}



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章