IOS之基础动画

来源:互联网 发布:编码器编程程序接线图 编辑:程序博客网 时间:2024/05/18 00:43

//

//  ViewController.m

//  基础动画

//

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

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

//


#import "ViewController.h"


@interface ViewController ()


@end


@implementation ViewController


- (void)viewDidLoad {

    [superviewDidLoad];

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

    view1.tag =200;

    view1.backgroundColor = [UIColorredColor];

    [self.viewaddSubview:view1];

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

    view2.backgroundColor = [UIColorgrayColor];

    view2.tag =100;

    [self.viewaddSubview:view2];

}

//触摸屏幕时调用

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

    [selfblockxchangeView];

}

//转场动画

-(void)exchangeView{

    [UIViewbeginAnimations:nilcontext:nil];

    [UIViewsetAnimationCurve:UIViewAnimationCurveLinear];

    [UIViewsetAnimationDuration:1.5];

    //设置转场效果

    [UIViewsetAnimationTransition:UIViewAnimationTransitionCurlUpforView:self.viewcache:YES];

    //实现转场

    UIView *view1 = [self.viewviewWithTag:200];

     UIView *view2 = [self.viewviewWithTag:100];

    NSInteger indexOfview1 = [self.view.subviewsindexOfObject:view1];

     NSInteger indexOfview2 = [self.view.subviewsindexOfObject:view2];

    [self.viewexchangeSubviewAtIndex:indexOfview1withSubviewAtIndex:indexOfview2];

    [UIViewcommitAnimations];

    

}

//block方式的转场动画

-(void)blockBaseAnimation{

    UIView *view2 = [self.viewviewWithTag:100];

    [UIViewanimateWithDuration:2animations:^{

        view2.alpha =0.2;

    }completion:^(BOOL finished) {

        [UIViewanimateWithDuration:2animations:^{

            view2.alpha =1;

        }];

    }];

}

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

-(void)blockxchangeView{

   

    [UIViewtransitionWithView:self.viewduration:2options:UIViewAnimationOptionTransitionFlipFromLeftanimations:^{

        [self.viewexchangeSubviewAtIndex:2withSubviewAtIndex:3];

    } completion:^(BOOL finished) {

        

    }];

}

//基础动画之缩小篇

-(void)baseAnimation{

    //开始动画

    [UIViewbeginAnimations:@"view1"context:@"缩小"];

    //设置动画加速方式

    [UIViewsetAnimationCurve:UIViewAnimationCurveEaseInOut];

    //动画时长

    [UIViewsetAnimationDuration:2.0];

    //设置代理

    [UIViewsetAnimationDelegate:self];

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

    [UIViewsetAnimationDidStopSelector:@selector(animationDidStop:finished:)];

    UIView *view2 = [self.viewviewWithTag: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 {

    [superdidReceiveMemoryWarning];

    // Dispose of any resources that can be recreated.

}


@end

0 0
原创粉丝点击