-
Notifications
You must be signed in to change notification settings - Fork 78
/
Copy pathHyTransitions.m
76 lines (59 loc) · 2.26 KB
/
HyTransitions.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
//
// HyTransitions.m
// Example
//
// Created by 东海 on 15/9/2.
// Copyright (c) 2015年 Jonathan Tribouharet. All rights reserved.
//
#import "HyTransitions.h"
@interface HyTransitions ()
@property (nonatomic, assign) NSTimeInterval transitionDuration;
@property (nonatomic, assign) CGFloat startingAlpha;
@property (nonatomic, assign) BOOL isPush;
@property (nonatomic, strong) id transitionContext;
@end
@implementation HyTransitions
- (instancetype)initWithTransitionDuration:(NSTimeInterval)transitionDuration StartingAlpha:(CGFloat)startingAlpha isPush:(BOOL)isPush {
self = [super init];
if (self) {
_transitionDuration = transitionDuration;
_startingAlpha = startingAlpha;
_isPush = isPush;
}
return self;
}
#pragma mark - UIViewControllerAnimatedTransitioning
- (NSTimeInterval)transitionDuration:(id <UIViewControllerContextTransitioning>)transitionContext {
return _transitionDuration;
}
- (void)animateTransition:(id <UIViewControllerContextTransitioning>)transitionContext{
UIView *containerView = [transitionContext containerView];
UIView *toView = [transitionContext viewControllerForKey:UITransitionContextToViewControllerKey].view;
UIView *fromView = [transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey].view;
if (_isPush) {
toView.alpha = _startingAlpha;
fromView.alpha = 1.0f;
[containerView addSubview:toView];
[UIView animateWithDuration:[self transitionDuration:transitionContext] animations:^{
toView.alpha = 1.0f;
fromView.alpha = 0.0f;
} completion:^(BOOL finished) {
fromView.alpha = 1.0f;
[transitionContext completeTransition:true];
}];
} else {
fromView.alpha = 1.0f;
toView.alpha = 0;
fromView.transform = CGAffineTransformMakeScale(1, 1);
[containerView addSubview:toView];
[UIView animateWithDuration:0.3 animations:^{
fromView.transform = CGAffineTransformMakeScale(3, 3);
fromView.alpha = 0.0f;
toView.alpha = 1.0f;
} completion:^(BOOL finished) {
fromView.alpha = 1.0f;
[transitionContext completeTransition:true];
}];
}
}
@end