动画分析:
1.弹出卡片(使用缩放功能)
2.textField和progressView结合,监听textField的值,当textField开始编辑的使用,progressView的progress的值从0.01变为1
3.当textField的值结束编辑的时候,如果textField的text为nil,progressView的progress重新变为0
4.当点击确定按钮的时候,让button进行缩放,整个view延时几秒后进行缩放
5.利用通知,让图片进行放大显示
ok,直接上代码
#import "ViewController.h"
#import "LoginInView.h"
@interface ViewController ()
@property (nonatomic, assign) CGAffineTransform transForm;
@property (nonatomic , strong) LoginInView *login;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
self.view.backgroundColor = [UIColor lightGrayColor];
UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(100, 100, 100, 100)];
[button setTitle:@"点我" forState:UIControlStateNormal];
[button setTintColor:[UIColor blueColor]];
[button addTarget:self action:@selector(touchMe:) forControlEvents:(UIControlEventTouchUpInside)];
button.center = self.view.center;
[self.view addSubview:button];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(thinkYou) name:@"thinks" object:nil];
}
-(void)touchMe:(UIButton *)sender{
_login = [[LoginInView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
// login.view.frame = CGRectZero;
[UIView animateWithDuration:0.3 animations:^{
sender.alpha = 0.0f;
} completion:^(BOOL finished) {
[self.view addSubview:_login];
}];;
_login.center = self.view.center;
_transForm = CGAffineTransformIdentity;
_transForm = CGAffineTransformMakeScale( 0.01, 0.01);
_login.transform = _transForm;
[UIView animateWithDuration:0.3 delay:0.4 options:(UIViewAnimationOptionCurveEaseInOut) animations:^{
_transForm = CGAffineTransformMakeScale(0.9, 0.9);
_login.transform = _transForm;
} completion:^(BOOL finished) {
}];
}
-(void)thinkYou{
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 200, 200)];
imageView.center = self.view.center;
imageView.image = [UIImage imageNamed:@"images.jpg"];
[self.view addSubview:imageView];
_transForm = CGAffineTransformMakeScale(0.01, 0.01);
imageView.transform = _transForm;
[UIView animateWithDuration:0.5 animations:^{
_transForm = CGAffineTransformMakeScale(0.9, 0.9);
imageView.transform = _transForm;
}];
}
-(void)viewWillDisappear:(BOOL)animated{
[self.view removeFromSuperview];
self.view = nil;
}
-(void)dealloc{
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
动画的view
#import "LoginInView.h"
#import <QuartzCore/QuartzCore.h>
@interface LoginInView ()<UITextFieldDelegate>
@property (nonatomic, strong) UIProgressView *progressView1;
@property (nonatomic, strong) UIProgressView *progressView2;
@property (nonatomic, assign) CGAffineTransform transForm;
@end
@implementation LoginInView
- (instancetype)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
self.backgroundColor = [UIColor whiteColor];
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 20, self.frame.size.width, 20)];
label.text = @"SIGN IN";
label.textAlignment = NSTextAlignmentCenter;
[self addSubview:label];
UITextField *text = [[UITextField alloc] initWithFrame:CGRectMake(20, 50, self.frame.size.width - 40, 40)];
text.placeholder = @"First Name";
text.delegate = self;
text.tag = 1000;
[text setTintColor:[UIColor blueColor]];
[self addSubview:text];
_progressView1 = [[UIProgressView alloc] initWithFrame:CGRectMake(20, 90, self.frame.size.width - 40, 2)];
_progressView1.progressTintColor = [UIColor blueColor];
_progressView1.progress = 0.01;
[self addSubview:_progressView1];
UITextField *text2 = [[UITextField alloc] initWithFrame:CGRectMake(20, 120, self.frame.size.width - 40, 50)];
text2.placeholder = @"Second Name";
text2.delegate = self;
text2.tag = 1001;
[text2 setTintColor:[UIColor blueColor]];
[self addSubview:text2];
_progressView2 = [[UIProgressView alloc] initWithFrame:CGRectMake(20, 170, self.frame.size.width - 40, 2)];
_progressView2.progressTintColor = [UIColor blueColor];
_progressView2.progress = 0.01;
[self addSubview:_progressView2];
UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(0, 200, self.frame.size.width - 0, 30)];
button.backgroundColor = [UIColor blueColor];
[button setTintColor:[UIColor whiteColor]];
[button setTitle:@"确定" forState:UIControlStateNormal];
[button addTarget:self action:@selector(define:) forControlEvents:(UIControlEventTouchUpInside)];
[self addSubview:button];
}
return self;
}
-(void)textFieldDidBeginEditing:(UITextField *)textField{
if (textField.tag == 1000) {
[_progressView1 setProgress:1.0f animated:YES];
}
if (textField.tag == 1001) {
[_progressView2 setProgress:1.0f animated:YES];
}
}
-(void)textFieldDidEndEditing:(UITextField *)textField{
if (textField.tag == 1000) {
if (textField.text.length == 0) {
[_progressView1 setProgress:0.01f animated:YES];
}
}else if(textField.tag == 1001){
if (textField.text.length == 0) {
[_progressView2 setProgress:0.01f animated:YES];
}
}
}
-(void)define:(UIButton *)button{
_transForm = CGAffineTransformIdentity;
[UIView animateWithDuration:0.3f animations:^{
_transForm = CGAffineTransformMakeScale(0.1, 0.1);
button.transform = _transForm;
}];
[UIView animateWithDuration:0.3f animations:^{
_transForm = CGAffineTransformMakeScale(0.1, 0.1);
button.transform = _transForm;
} completion:^(BOOL finished) {
[UIView animateWithDuration:0.3 delay:0.3 options:UIViewAnimationOptionCurveEaseInOut animations:^{
_transForm = CGAffineTransformMakeScale(0.1, 0.1);
self.transform = _transForm;
} completion:^(BOOL finished) {
[self removeFromSuperview];
[[NSNotificationCenter defaultCenter] postNotificationName:@"thinks" object:self];
}];
}];
}