IOS之基础动画

//

//  ViewController.m

//  基础动画

//

//  Created by 李江 on 16/5/12.

//  Copyright © 2016 李江. All rights reserved.

//


#import "ViewController.h"


@interface ViewController ()


@end


@implementation ViewController


- (void)viewDidLoad {

    [super viewDidLoad];

    UIView *view1 = [[UIView alloc]initWithFrame:self.view.frame];

    view1.tag = 200;

    view1.backgroundColor = [UIColor redColor];

    [self.view addSubview:view1];

    UIView *view2 = [[UIView alloc]initWithFrame:self.view.frame];

    view2.backgroundColor = [UIColor grayColor];

    view2.tag = 100;

    [self.view addSubview:view2];

}

//触摸屏幕时调用

-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{

    [self blockxchangeView];

}

//转场动画

-(void)exchangeView{

    [UIView beginAnimations:nil context:nil];

    [UIView setAnimationCurve:UIViewAnimationCurveLinear];

    [UIView setAnimationDuration:1.5];

    //设置转场效果

    [UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:self.view cache:YES];

    //实现转场

    UIView *view1 = [self.view viewWithTag:200];

     UIView *view2 = [self.view viewWithTag:100];

    NSInteger indexOfview1 = [self.view.subviews indexOfObject:view1];

     NSInteger indexOfview2 = [self.view.subviews indexOfObject:view2];

    [self.view exchangeSubviewAtIndex:indexOfview1 withSubviewAtIndex:indexOfview2];

    [UIView commitAnimations];

    

}

//block方式的转场动画

-(void)blockBaseAnimation{

    UIView *view2 = [self.view viewWithTag:100];

    [UIView animateWithDuration:2 animations:^{

        view2.alpha = 0.2;

    }completion:^(BOOL finished) {

        [UIView animateWithDuration:2 animations:^{

            view2.alpha = 1;

        }];

    }];

}

//另一种block方式的专场动画

-(void)blockxchangeView{

   

    [UIView transitionWithView:self.view duration:2 options:UIViewAnimationOptionTransitionFlipFromLeft animations:^{

        [self.view exchangeSubviewAtIndex:2 withSubviewAtIndex:3];

    } completion:^(BOOL finished) {

        

    }];

}

//基础动画之缩小篇

-(void)baseAnimation{

    //开始动画

    [UIView beginAnimations:@"view1" context:@"缩小"];

    //设置动画加速方式

    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];

    //动画时长

    [UIView setAnimationDuration:2.0];

    //设置代理

    [UIView setAnimationDelegate:self];

    //指定动画结束时执行的方法

    [UIView setAnimationDidStopSelector:@selector(animationDidStop:finished:)];

    UIView *view2 = [self.view viewWithTag:100];

    CGRect rect  = view2.frame;

    rect.size = CGSizeMake(100, 100);

    view2.frame = rect;

    view2.center =self.view.center;

}

-(void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag{

    

}

- (void)didReceiveMemoryWarning {

    [super didReceiveMemoryWarning];

    // Dispose of any resources that can be recreated.

}


@end

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值