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

#import "FlipAnimation.h"

@implementation FlipAnimation

-(void)start
{
    CATransform3D  originTransform = _targetView.layer.transform;
    NSArray<NSNumber *> *keyTimes =  @[@0,@0.4,@0.5,@0.8,@1];
    NSArray<CAMediaTimingFunction *> * timeFunctions  = @[
                                                          [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut],
                                                          [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut],
                                                          [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn],                                                          [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn],                                                          [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn],
                                                          ];


    NSArray * values = @[
                         [NSValue valueWithCATransform3D: CATransform3DConcat(CATransform3DPerspective(originTransform,400), CATransform3DRotate(originTransform, deg(-360), 0, 1, 0))
                          ],
                         [NSValue valueWithCATransform3D:CATransform3DTranslate(CATransform3DRotate(CATransform3DPerspective(originTransform,400), deg(-190), 0, 1, 0), 0, 0, 150)
                          ],
                         [NSValue valueWithCATransform3D:CATransform3DTranslate(CATransform3DRotate(CATransform3DPerspective(originTransform,400), deg(-170), 0, 1, 0), 0, 0, 150)
                          ],
                         [NSValue valueWithCATransform3D:
                          CATransform3DScale(CATransform3DPerspective(originTransform,400), 0.9, 0.9, 0.9)
                          ],
                         [NSValue valueWithCATransform3D:(CATransform3DPerspective(originTransform,400))
                          ]
                         ];
    
    CAKeyframeAnimation * transformAnimation = [CAKeyframeAnimation animationWithKeyPath:@"transform"];
    transformAnimation.keyTimes = keyTimes;
    transformAnimation.timingFunctions = timeFunctions;
    transformAnimation.values = values;
    
    
    
    CAAnimationGroup * animationGroup = [[CAAnimationGroup alloc] init];
    animationGroup.animations = @[transformAnimation];
    animationGroup.delegate= self;
    animationGroup.duration = _params.duration;
    [_targetView.layer addAnimation:animationGroup forKey:@""];
    
    
}

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