iOS 2D仿射的使用

2D仿射总结

2D仿射的基础原理
实现的登录效果动画,动画参考

动画效果.gif

动画分析:
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];
        
    }];
}];

}
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 174,081评论 25 709
  • 文|| 梅子黄黄 朋友A说小时候妈妈总爱挑他的刺,渐渐地他发觉自己为了反抗妈妈,也总能找到妈妈的痛点来反击她。后来...
    倾心悦见阅读 794评论 0 3
  • 这是一个两分钟决定命运的时代 良好的形象,是一个人安身立命的基本。我们都知道谁都喜欢形象出色的人,而不愿意接近形象...
    山东_龙游天下阅读 617评论 2 8
  • 白天的忙碌,终于让我有了疲惫的感觉。 本想做完节目,回来直接就睡觉了。 结果还是没有控制住我自己。 如果有你就好了...
    她的简书阅读 182评论 0 0
  • 本文首载于 Gevin的博客 基于一些不错的RESTful开发组件,可以快速的开发出不错的RESTful API,...
    Gevin阅读 11,985评论 6 111