iOS Core Animation (本人写的源码)

//

//  ViewController.h

//  Animation_byEpisode

//

//  Created by Wangyun on 15/7/9.

//  Copyright (c) 2015 com.epsiode. All rights reserved.

//


#import <UIKit/UIKit.h>


@interface ViewController : UIViewController


@end


//  ViewController.m

//  Animation_byEpisode

//

//  Created by Wangyun on 15/7/9.

//  Copyright (c) 2015 com.epsiode. All rights reserved.

//


#import "ViewController.h"

#import "SecondViewController.h"



NSString * const string = @"123";



@interface ViewController ()


@property (strong, nonatomic) IBOutlet UIImageView *imageView;

@property (strong, nonatomic) IBOutlet UIImageView *colorImageView;

@property(nonatomic,retain) SecondViewController *secondVC;




@end


@implementation ViewController


- (void)viewDidLoad {

    [super viewDidLoad];

    self.imageView.image=[UIImage imageNamed:@"10042637.jpg"];

    self.imageView.layer.cornerRadius=20;

    self.imageView.layer.borderWidth=2;

    self.imageView.layer.borderColor=[UIColor greenColor].CGColor;

    self.imageView.layer.shadowColor=[[UIColor blueColor] CGColor];

    self.imageView.layer.shadowOffset=CGSizeMake(20, 20);

    self.imageView.layer.shadowOpacity=0.5;

    [self.imageView setClipsToBounds:YES];

    //超过主层边框范围的内容都裁剪

    self.imageView.layer.masksToBounds=NO;

    

    //[self testImageView];

    

    self.colorImageView.backgroundColor=[UIColor purpleColor];

    self.colorImageView.layer.cornerRadius=20;

    self.colorImageView.layer.borderWidth=2;

    self.colorImageView.layer.borderColor=[UIColor greenColor].CGColor;

    self.colorImageView.layer.shadowColor=[[UIColor yellowColor] CGColor];

    self.colorImageView.layer.shadowOffset=CGSizeMake(20, 20);

    self.colorImageView.layer.shadowOpacity=0.5;

    [self.colorImageView setClipsToBounds:YES];

    self.colorImageView.layer.masksToBounds=NO;


    self.secondVC=[self.storyboard instantiateViewControllerWithIdentifier:@"secondVC"];

}


-(void)testImageView{

    //[self.imageView.layer setValue:@(M_PI_4) forKeyPath:@"transform.rotation"];

//    NSValue *value=[NSValue valueWithCATransform3D:CATransform3DMakeRotation(M_PI_4, 0, 0, 1)];

//    [self.imageView.layer setValue:value forKeyPath:@"transform"];

    //[self.imageView.layer setValue:[NSValue valueWithCATransform3D:CATransform3DMakeRotation(M_PI_4, 0, 0, 1)] forKeyPath:@"transform"];

   // [self.imageView.layer setValue:[NSNumber numberWithFloat:0.5] forKeyPath:@"transform.scale.y"];

    [self.imageView.layer setValue:@(0.5) forKeyPath:@"transform.scale.y"];

}


//UIView动画的动画块方法

- (IBAction)propertyAnimation:(UIButton *)sender {

    [UIView beginAnimations:@"AnimationOne" context:nil];

    [UIView setAnimationDuration:1];

    [UIView setAnimationRepeatCount:2];

    //[UIView setAnimationDelegate:self];  这个有什么用??

    self.colorImageView.bounds=CGRectMake(120, 80, 100, 100);

    self.colorImageView.layer.cornerRadius=50;

    self.colorImageView.transform=CGAffineTransformMakeRotation(M_PI);

    [UIView commitAnimations];

}


//UIView动画的block方法

- (IBAction)blockAnimation:(UIButton *)sender {

    [UIView animateWithDuration:1 delay:1 options:UIViewAnimationOptionTransitionFlipFromBottom animations:^{

        self.colorImageView.bounds=CGRectMake(0, 0, 200, 200);

        self.colorImageView.transform=CGAffineTransformMakeRotation(2*M_PI);

    } completion:^(BOOL finished) {

        

    }];

}



- (IBAction)transmitAnimation:(UIButton *)sender {

    UIView *view=self.view.superview;

    [UIView beginAnimations:@"transmit" context:nil];

    [UIView setAnimationDuration:3];

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

    [self.view removeFromSuperview];

    [view addSubview:self.secondVC.view];

    [UIView commitAnimations];

    

}


//UIViewTransitionAPI方法

- (IBAction)blockTransmitAnimation:(UIButton *)sender {

    [UIView transitionFromView:self.view toView:self.secondVC.view duration:1 options:UIViewAnimationOptionTransitionCurlUp completion:^(BOOL finished) {

        

    }];

    UIView *view=self.view.superview;

    [UIView transitionWithView:view duration:1 options:UIViewAnimationOptionTransitionCurlUp animations:^{

        [self.view removeFromSuperview];

        [view addSubview:self.secondVC.view];

    } completion:^(BOOL finished) {

        

    }];

}


//CAAnimation是抽象类,CAPropertyAnimation-->CABasicAnimation

- (IBAction)basicAnimation:(UIButton *)sender {

    CABasicAnimation *basicAnimation=[CABasicAnimation animationWithKeyPath:@"backgroundColor"];

    basicAnimation.duration=6;

        basicAnimation.fromValue = (__bridge id)([[UIColor redColor] CGColor]);

        basicAnimation.toValue = (__bridge id)([[UIColor purpleColor] CGColor]);

//        basicAnimation.fromValue = [NSNumber numberWithFloat:0.5];

//        basicAnimation.byValue = [NSNumber numberWithFloat:0.2];

    [self.colorImageView.layer addAnimation:basicAnimation forKey:@"haha"];

    self.colorImageView.backgroundColor=[UIColor yellowColor];

}


//CAAnimation是抽象类,CAPropertyAnimation-->CAKeyFrameAnimation

- (IBAction)keyFrameAnimation:(UIButton *)sender {

    CAKeyframeAnimation *keyFrameAnimation=[CAKeyframeAnimation animationWithKeyPath:@"position.x"];

    CGFloat center=self.colorImageView.layer.position.x;

    CGFloat left=center-20;

    CGFloat right=center+20;

    NSNumber *c=[NSNumber numberWithFloat:center];

    NSNumber *l=[NSNumber numberWithFloat:left];

    NSNumber *r=[NSNumber numberWithFloat:right];

    keyFrameAnimation.values=@[c,r,l,c,l,r,c,r,l,r,c,l];

    [self.colorImageView.layer addAnimation:keyFrameAnimation forKey:@"shake"];

}


//CATransition,作⽤:layer的过渡动画

//有两个主要属性:type(设置过渡动画的效果)subType(设置过渡 动画的⽅方向)

- (IBAction)coreAnimation:(UIButton *)sender {

    CATransition *transition=[CATransition animation];

    transition.duration=3;

    transition.startProgress=0.5;

    transition.type=@"cube";

    transition.subtype=kCATransitionFromLeft;

    UIView *view = self.view.superview;

    [view.layer addAnimation:transition forKey:@"过渡"];

    [self.view removeFromSuperview];

    [view addSubview:self.secondVC.view];

}


//CAAnimation是抽象类,CAAnimationGroup-->CAAnimationGroup只有⼀一个数组属性,可以添加多个 CAAnimation,⼀一起执⾏行

- (IBAction)groupAnimation:(UIButton *)sender {

    CAAnimationGroup *groupAnimation=[CAAnimationGroup animation];

    

    CABasicAnimation *basicAnimation=[CABasicAnimation animationWithKeyPath:@"position"];

    basicAnimation.fromValue=[NSValue valueWithCGPoint:self.colorImageView.layer.position];

    basicAnimation.toValue=[NSValue valueWithCGPoint:CGPointMake(50, 300)];

 

    

    CABasicAnimation *basicAnimation1=[CABasicAnimation animationWithKeyPath:@"color"];

    basicAnimation1.fromValue = (__bridge id)([[UIColor redColor] CGColor]);

    basicAnimation1.toValue = (__bridge id)([[UIColor purpleColor] CGColor]);


    

    groupAnimation.duration=3;

    groupAnimation.animations=@[basicAnimation,basicAnimation1];

    [self.colorImageView.layer addAnimation:groupAnimation forKey:@"2"];

}


- (void)didReceiveMemoryWarning {

    [super didReceiveMemoryWarning];

    // Dispose of any resources that can be recreated.

}


@end


//  FirstViewController.h

//  Animation_byEpisode

//

//  Created by Wangyun on 15/7/9.

//  Copyright (c) 2015 com.epsiode. All rights reserved.

//


#import <UIKit/UIKit.h>


@interface FirstViewController : UIViewController


@end

//  FirstViewController.m

//  Animation_byEpisode

//

//  Created by Wangyun on 15/7/9.

//  Copyright (c) 2015 com.epsiode. All rights reserved.

//


#import "FirstViewController.h"

#import "Macro.h"

#import "ViewController.h"


@interface FirstViewController ()


@end


@implementation FirstViewController


- (void)viewDidLoad {

    [super viewDidLoad];

    [self bootAnimation];

}

-(void)bootAnimation{

    UIImageView *bootImageView=[[UIImageView alloc] initWithFrame:[UIScreen mainScreen].bounds];

    bootImageView.image=[UIImage imageNamed:@"zhiyan"];

    [self.view addSubview:bootImageView];

    [UIView animateWithDuration:3 delay:0 options:UIViewAnimationOptionOverrideInheritedDuration animations:^{

        bootImageView.frame=CGRectMake(-30, -50, kScreen_Width+60, kScreen_Height+100);

    } completion:^(BOOL finished) {

        [bootImageView removeFromSuperview];

        ViewController *viewC=[self.storyboard instantiateViewControllerWithIdentifier:@"viewVC"];

        //[self.view removeFromSuperview];

        [self.view addSubview:viewC.view];

    }];

}


- (void)didReceiveMemoryWarning {

    [super didReceiveMemoryWarning];

    // Dispose of any resources that can be recreated.

}


/*

#pragma mark - Navigation


// In a storyboard-based application, you will often want to do a little preparation before navigation

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {

    // Get the new view controller using [segue destinationViewController].

    // Pass the selected object to the new view controller.

}

*/


@end

//

//  SecondViewController.h

//  Animation_byEpisode

//

//  Created by Wangyun on 15/7/9.

//  Copyright (c) 2015 com.epsiode. All rights reserved.

//


#import <UIKit/UIKit.h>


extern NSString * const string;


@interface SecondViewController : UIViewController


@end


//  SecondViewController.m

//  Animation_byEpisode

//

//  Created by Wangyun on 15/7/9.

//  Copyright (c) 2015 com.epsiode. All rights reserved.

//


#import "SecondViewController.h"

#import "ViewController.h"


@interface SecondViewController ()

@property(nonatomic,retain) ViewController *viewController;

@end


@implementation SecondViewController


- (void)viewDidLoad {

    [super viewDidLoad];

    NSLog(@"string :%@",string);

    

    _viewController=[self.storyboard instantiateViewControllerWithIdentifier:@"viewVC"];

}


- (IBAction)swiftBack:(UIButton *)sender {

    [UIView transitionFromView:self.view toView:self.viewController.view duration:1 options:UIViewAnimationOptionTransitionCurlDown completion:^(BOOL finished) {

        

    }];

    UIView *view=self.view.superview;

    [UIView transitionWithView:view duration:1 options:UIViewAnimationOptionTransitionCurlDown animations:^{

        [self.view removeFromSuperview];

        [view addSubview:self.viewController.view];

    } completion:^(BOOL finished) {

        

    }];

}


- (void)didReceiveMemoryWarning {

    [super didReceiveMemoryWarning];

    // Dispose of any resources that can be recreated.

}


/*

#pragma mark - Navigation


// In a storyboard-based application, you will often want to do a little preparation before navigation

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {

    // Get the new view controller using [segue destinationViewController].

    // Pass the selected object to the new view controller.

}

*/


@end



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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值