//
//  FlipOutYAnimation.m
//  TTAnimationExample
//
//  Created by titengjiang on 16/1/19.
//  Copyright 漏 2016骞?sloop. All rights reserved.
//

#import "FlipOutYAnimation.h"

@implementation FlipOutYAnimation

-(void)start
{
    NSArray<NSNumber *> *keyTimes =  @[@0,@0.3,@1];
    CATransform3D  originTransform = _targetView.layer.transform;
    
    
    NSArray * values = @[
                         [NSValue valueWithCATransform3D: CATransform3DPerspective(originTransform,400)
                          ],
                         [NSValue valueWithCATransform3D:CATransform3DRotate(CATransform3DPerspective(originTransform,400), deg(-20), 0, 1, 0)
                          ],
                         [NSValue valueWithCATransform3D:CATransform3DRotate(CATransform3DPerspective(originTransform,400), deg(90), 0, 1, 0)
                          ]
                         ];
    
    CAKeyframeAnimation * transformAnimation = [CAKeyframeAnimation animationWithKeyPath:@"transform"];
    transformAnimation.keyTimes = keyTimes;
    transformAnimation.values = values;
    
    
    CAKeyframeAnimation * opacityAnimation = [CAKeyframeAnimation animationWithKeyPath:@"opacity"];
    opacityAnimation.keyTimes =@[@0,@0.3,@1];
    opacityAnimation.values = @[@1,@1,@0];
    
    CAAnimationGroup * animationGroup = [[CAAnimationGroup alloc] init];
    animationGroup.animations = @[transformAnimation,opacityAnimation];
    animationGroup.delegate= self;
    animationGroup.duration = _params.duration;
    animationGroup.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionDefault];
    [_targetView.layer addAnimation:animationGroup forKey:@""];
}

@end
// 鐗堟潈灞炰簬鍘熶綔鑰?// http://code4app.com (cn) http://code4app.net (en)
// 鍙戝竷浠g爜浜庢渶涓撲笟鐨勬簮鐮佸垎浜綉绔? Code4App.com