Snail—UI学习之动画Animations

本文主要探讨Snail-UI库中的动画Animations,通过示例代码展示其使用方法,虽然当前分析较为简洁,但未来将进行深入讲解。
摘要由CSDN通过智能技术生成

直接上代码,看的不深,以后再做详细讲解

#import "WJJRootViewController.h"

@interface WJJRootViewController (){
    //把view设为全局变量
    UIView * _view;
}

@end

@implementation WJJRootViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor grayColor];
    _view = [[UIView alloc] initWithFrame:CGRectMake(300, 400, 20, 20)];
    _view.tag = 250;
    _view.backgroundColor = [UIColor purpleColor];
    [self.view addSubview:_view];
    //动画执行第一种方法
    UIButton * button1 = [UIButton buttonWithType:UIButtonTypeSystem];
    button1.tag = 1;
    button1.frame = CGRectMake(0, 460, 50, 20);
    button1.backgroundColor = [UIColor yellowColor];
    [button1 setTitle:@"动画1" forState:UIControlStateNormal];
    [button1 addTarget:self action:@selector(change:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:button1];
    
    //动画执行第一种方法
    UIButton * button2 = [UIButton buttonWithType:UIButtonTypeSystem];
    button2.tag = 2;
    button2.frame = CGRectMake(60, 460, 50, 20);
    button2.backgroundColor = [UIColor yellowColor];
    [button2 setTitle:@"动画2" forState:UIControlStateNormal];
    [button2 addTarget:self action:@selector(change:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:button2];
    
    //动画执行第一种方法
    UIButton * button3 = [UIButton buttonWithType:UIButtonTypeSystem];
    button3.tag = 3;
    button3.frame = CGRectMake(120, 460, 50, 20);
    button3.backgroundColor = [UIColor yellowColor];
    [button3 setTitle:@"动画3" forState:UIControlStateNormal];
    [button3 addTarget:self action:@selector(change:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:button3];
    
}

- (void)change:(UIButton *)button{
    
    if (button.tag == 1) {
        //动画执行前的准备
        [UIView beginAnimations:nil context:nil];
        //动画执行的时间
        [UIView setAnimationDuration:10];
        //动画执行的 也就是要看到的动画效果
        _view.frame = CGRectMake(0, 20, 50, 50);
        _view.backgroundColor = [UIColor blackColor];
        //动画执行
        [UIView commitAnimations];
    }else if (button.tag == 2){
        //动画持续10s,block中写的就是要实现的最终动画结果
        [UIView animateWithDuration:10 animations:^{
            _view.frame = CGRectMake(0, 20, 50, 50);
            _view.backgroundColor = [UIColor blackColor];
        }];
        
    }else if (button.tag == 3){
        //第一个block是第一次实现的动画效果 第二个block是第一个动画效果完成后执行的另一个动画
        [UIView animateWithDuration:4 animations:^{
            _view.frame = CGRectMake(0, 20, 50, 50);
            _view.backgroundColor = [UIColor blackColor];
        } completion:^(BOOL finshed){
            
            [UIView animateWithDuration:10 animations:^{
                _view.frame = CGRectMake(300, 440, 20, 20);
                _view.backgroundColor = [UIColor blackColor];
            }];

        }];
    }
    
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值