Skip to content

Commit c33d0e2

Browse files
committed
Merge pull request IFTTT#1688 from ashavit/mask_animation
Swipe Animation
2 parents 3b90734 + b1d085f commit c33d0e2

File tree

11 files changed

+1298
-1108
lines changed

11 files changed

+1298
-1108
lines changed

Example/Pods/Headers/Private/JazzHands/IFTTTMaskAnimation.h

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Example/Pods/Headers/Private/Masonry/ViewController+MASAdditions.h

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Example/Pods/Headers/Public/JazzHands/IFTTTMaskAnimation.h

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Example/Pods/Headers/Public/Masonry/ViewController+MASAdditions.h

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Example/Pods/Masonry/Masonry/ViewController+MASAdditions.h

+25
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Example/Pods/Masonry/Masonry/ViewController+MASAdditions.m

+25
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Example/Pods/Pods.xcodeproj/project.pbxproj

+1,123-1,107
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Example/Pods/Pods.xcodeproj/xcshareddata/xcschemes/JazzHands.xcscheme

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

JazzHands/IFTTTJazzHands.h

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#import "IFTTTAnimatedPagingScrollViewController.h"
2323

2424
#import "IFTTTAlphaAnimation.h"
25+
#import "IFTTTMaskAnimation.h"
2526
#import "IFTTTCornerRadiusAnimation.h"
2627
#import "IFTTTFrameAnimation.h"
2728
#import "IFTTTHideAnimation.h"

JazzHands/IFTTTMaskAnimation.h

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
//
2+
// IFTTTMaskAnimation.h
3+
// JazzHands
4+
//
5+
// Created by Amir Shavit on 7/26/15.
6+
// Copyright (c) 2015 IFTTT Inc. All rights reserved.
7+
//
8+
9+
#import "IFTTTAnimation.h"
10+
11+
typedef NS_ENUM(NSUInteger, IFTTTMaskSwipeDirection)
12+
{
13+
IFTTTMaskSwipeFromTop,
14+
IFTTTMaskSwipeFromLeft,
15+
IFTTTMaskSwipeFromBottom,
16+
IFTTTMaskSwipeFromRight
17+
};
18+
19+
@interface IFTTTMaskAnimation : IFTTTAnimation <IFTTTAnimatable>
20+
21+
- (instancetype)initWithView:(UIView *)view direction:(IFTTTMaskSwipeDirection)direction NS_DESIGNATED_INITIALIZER;
22+
+ (instancetype)animationWithView:(UIView *)view direction:(IFTTTMaskSwipeDirection)direction;
23+
24+
- (void)addKeyframeForTime:(CGFloat)time visibility:(CGFloat)percent;
25+
- (void)addKeyframeForTime:(CGFloat)time visibility:(CGFloat)percent withEasingFunction:(IFTTTEasingFunction)easingFunction;
26+
27+
@end

JazzHands/IFTTTMaskAnimation.m

+92
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
//
2+
// IFTTTMaskAnimation.m
3+
// JazzHands
4+
//
5+
// Created by Amir Shavit on 7/26/15.
6+
// Copyright (c) 2015 IFTTT Inc. All rights reserved.
7+
//
8+
9+
#import "IFTTTMaskAnimation.h"
10+
11+
@interface IFTTTMaskAnimation ()
12+
13+
@property (nonatomic, strong) UIView* maskedView;
14+
@property (nonatomic, assign) IFTTTMaskSwipeDirection direction;
15+
16+
@end
17+
18+
@implementation IFTTTMaskAnimation
19+
20+
#pragma mark - Init
21+
22+
- (instancetype)initWithView:(UIView *)view direction:(IFTTTMaskSwipeDirection)direction
23+
{
24+
if ((self = [super init])) {
25+
_maskedView = view;
26+
_direction = direction;
27+
}
28+
return self;
29+
}
30+
31+
+ (instancetype)animationWithView:(UIView *)view direction:(IFTTTMaskSwipeDirection)direction
32+
{
33+
return [[self alloc] initWithView:view direction:direction];
34+
}
35+
36+
#pragma mark - Public Methods
37+
38+
- (void)addKeyframeForTime:(CGFloat)time visibility:(CGFloat)percent
39+
{
40+
[self addKeyframeForTime:time value:@(percent)];
41+
}
42+
43+
- (void)addKeyframeForTime:(CGFloat)time visibility:(CGFloat)percent withEasingFunction:(IFTTTEasingFunction)easingFunction
44+
{
45+
[self addKeyframeForTime:time value:@(percent) withEasingFunction:easingFunction];
46+
}
47+
48+
#pragma mark - IFTTTAnimatable Protocol
49+
50+
- (void)animate:(CGFloat)time
51+
{
52+
if (!self.hasKeyframes) return;
53+
CGFloat visibilityPercent = ((NSNumber *)[self valueAtTime:time]).floatValue;
54+
55+
CGRect maskedRect = self.maskedView.bounds;
56+
switch (self.direction)
57+
{
58+
case IFTTTMaskSwipeFromTop:
59+
{
60+
maskedRect.size.height *= visibilityPercent;
61+
break;
62+
}
63+
case IFTTTMaskSwipeFromLeft:
64+
{
65+
maskedRect.size.width *= visibilityPercent;
66+
break;
67+
}
68+
case IFTTTMaskSwipeFromBottom:
69+
{
70+
maskedRect.size.height *= visibilityPercent;
71+
maskedRect.origin.y = CGRectGetMaxY(self.maskedView.bounds) - maskedRect.size.height;
72+
break;
73+
}
74+
case IFTTTMaskSwipeFromRight:
75+
{
76+
maskedRect.size.width *= visibilityPercent;
77+
maskedRect.origin.x = CGRectGetMaxX(self.maskedView.bounds) - maskedRect.size.width;
78+
break;
79+
}
80+
81+
default:
82+
break;
83+
}
84+
85+
UIBezierPath* maskPath = [UIBezierPath bezierPathWithRect:maskedRect];
86+
87+
CAShapeLayer* maskLayer = [CAShapeLayer new];
88+
maskLayer.path = maskPath.CGPath;
89+
self.maskedView.layer.mask = maskLayer;
90+
}
91+
92+
@end

0 commit comments

Comments
 (0)