CAAnimation+VLCWiggle.m 2.5 KB
Newer Older
Tobias's avatar
Tobias committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14
/*****************************************************************************
 * VLC for iOS
 *****************************************************************************
 * Copyright (c) 2015 VideoLAN. All rights reserved.
 * $Id$
 *
 * Authors: Tobias Conradi <videolan # tobias-conradi.de>
 *
 * Refer to the COPYING file of the official project for license.
 *****************************************************************************/

#import "CAAnimation+VLCWiggle.h"

@implementation CAAnimation (VLCWiggle)
15
+ (instancetype)vlc_wiggleAnimationwithSoftMode:(BOOL)softmode
Tobias's avatar
Tobias committed
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
{
    CAKeyframeAnimation *position = [CAKeyframeAnimation animation];
    position.keyPath = @"position";
    position.values = @[
                        [NSValue valueWithCGPoint:CGPointZero],
                        [NSValue valueWithCGPoint:CGPointMake(-1, 0)],
                        [NSValue valueWithCGPoint:CGPointMake(1, 0)],
                        [NSValue valueWithCGPoint:CGPointMake(-1, 1)],
                        [NSValue valueWithCGPoint:CGPointMake(1, -1)],
                        [NSValue valueWithCGPoint:CGPointZero]
                        ];
    position.timingFunctions = @[
                                 [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut],
                                 [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]
                                 ];
    position.additive = YES;

    CAKeyframeAnimation *rotation = [CAKeyframeAnimation animation];
    rotation.keyPath = @"transform.rotation";
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
    if (softmode) {
        rotation.values = @[
                            @0,
                            @0.005,
                            @0,
                            [NSNumber numberWithFloat:-0.004]
                            ];
    } else {
        rotation.values = @[
                            @0,
                            @0.03,
                            @0,
                            [NSNumber numberWithFloat:-0.02]
                            ];
    }
Tobias's avatar
Tobias committed
50 51 52 53 54 55 56 57 58 59 60 61
    rotation.timingFunctions = @[
                                 [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut],
                                 [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]
                                 ];

    CAAnimationGroup *group = [[CAAnimationGroup alloc] init];
    group.animations = @[position, rotation];
    group.duration = 0.4;
    group.repeatCount = HUGE_VALF;
    return group;
}
@end