Skip to content

Commit

Permalink
统一API,AnimationStyleBackScale只做底部控制器动画,上层抛给用户
Browse files Browse the repository at this point in the history
  • Loading branch information
hxw committed Aug 7, 2019
1 parent 3edc87b commit 341f482
Show file tree
Hide file tree
Showing 13 changed files with 94 additions and 124 deletions.
2 changes: 1 addition & 1 deletion HHTransition.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'HHTransition'
s.version = '1.2.0'
s.version = '2.0.0'
s.summary = 'Transition'
s.description = 'Mainstream transition animation'
s.homepage = 'https://github.com/yuwind/HHTransition/wiki'
Expand Down
2 changes: 0 additions & 2 deletions HHTransition/AnimationFadeBegin.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,4 @@

@interface AnimationFadeBegin : NSObject<UIViewControllerAnimatedTransitioning>

+ (instancetype)animationHeight:(CGFloat)height;

@end
21 changes: 1 addition & 20 deletions HHTransition/AnimationFadeBegin.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,8 @@
#import "AnimationFadeBegin.h"
#import "AnimationStyle.h"

@interface AnimationFadeBegin()

@property (nonatomic, assign) CGFloat height;

@end

@implementation AnimationFadeBegin

+ (instancetype)animationHeight:(CGFloat)height
{
AnimationFadeBegin *fadeBegin = [[AnimationFadeBegin alloc] init];
fadeBegin.height = height;
return fadeBegin;
}

- (NSTimeInterval)transitionDuration:(id<UIViewControllerContextTransitioning>)transitionContext
{
return 0.4;
Expand All @@ -33,7 +20,7 @@ - (void)animateTransition:(id<UIViewControllerContextTransitioning>)transitionCo
{
UIViewController * toVC =
[transitionContext viewControllerForKey:UITransitionContextToViewControllerKey];
toVC.view.frame = CGRectMake(0, [UIScreen mainScreen].bounds.size.height, [UIScreen mainScreen].bounds.size.width, self.height?:[UIScreen mainScreen].bounds.size.height);
toVC.view.frame = CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height);
[[transitionContext containerView] addSubview:toVC.view];
toVC.view.layer.zPosition = MAXFLOAT;

Expand Down Expand Up @@ -63,12 +50,6 @@ - (void)animateTransition:(id<UIViewControllerContextTransitioning>)transitionCo
[transitionContext completeTransition:YES];
}];
}];

[UIView animateWithDuration:0.4 delay:0 options:UIViewAnimationOptionCurveEaseInOut animations:^{
CGRect frame = toVC.view.frame;
frame.origin.y = [UIScreen mainScreen].bounds.size.height - self.height?:[UIScreen mainScreen].bounds.size.height;
toVC.view.frame = frame;
} completion:nil];
}


Expand Down
2 changes: 0 additions & 2 deletions HHTransition/AnimationFadeEnd.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,4 @@

@interface AnimationFadeEnd : NSObject<UIViewControllerAnimatedTransitioning>

+ (instancetype)animationHeight:(CGFloat)height;

@end
16 changes: 0 additions & 16 deletions HHTransition/AnimationFadeEnd.m
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,6 @@ @interface AnimationFadeEnd()

@implementation AnimationFadeEnd

+ (instancetype)animationHeight:(CGFloat)height
{
AnimationFadeEnd *fadeEnd = [[AnimationFadeEnd alloc] init];
fadeEnd.height = height;
return fadeEnd;
}
- (NSTimeInterval)transitionDuration:(id<UIViewControllerContextTransitioning>)transitionContext
{
return 0.4;
Expand All @@ -32,9 +26,6 @@ - (void)animateTransition:(id<UIViewControllerContextTransitioning>)transitionCo
{
UIViewController * toVC =
[transitionContext viewControllerForKey:UITransitionContextToViewControllerKey];

UIViewController * fromVC =
[transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey];

CATransform3D rotate = CATransform3DIdentity;
rotate.m34 = -1.0 / 1000.0;
Expand All @@ -57,13 +48,6 @@ - (void)animateTransition:(id<UIViewControllerContextTransitioning>)transitionCo
[transitionContext completeTransition:YES];
}];
}];

[UIView animateWithDuration:0.4 delay:0 options:UIViewAnimationOptionCurveEaseInOut animations:^{

CGRect frame = fromVC.view.frame;
frame.origin.y = [UIScreen mainScreen].bounds.size.height;
fromVC.view.frame = frame;
} completion:nil];
}


Expand Down
45 changes: 10 additions & 35 deletions HHTransition/UIViewController+HHTransition.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,55 +15,31 @@ NS_ASSUME_NONNULL_BEGIN

@interface UIViewController (HHPresent)

@property (nonatomic, assign) AnimationStyle animationStyle;
@property (nonatomic, assign, readonly) AnimationStyle animationStyle;
@property (nonatomic, strong, readonly) VCInteractionDelegate *interactionDelegate;

/**
背部缩隐式
@param controller 控制器
@param height 控制器高度
@param completion 回调函数
*/
- (void)hh_presentBackScaleVC:(UIViewController *)controller height:(CGFloat)height completion:(void (^ __nullable)(void))completion;

/**
圆形放大式
ViewController transition, Partial style available
detail in "AnimationStyle.h"
@param controller 控制器
@param point 触摸点
@param completion 回调函数
*/
- (void)hh_presentCircleVC:(UIViewController *)controller point:(CGPoint)point completion:(void (^__nullable)(void))completion;
- (void)hh_presentVC:(UIViewController *)controller type:(AnimationStyle)style completion:(void (^__nullable)(void))completion;

/**
旋转样式
Circular enlargement transition, Need to pass the param `touch point`
@param controller 控制器
@param completion 回调函数
*/
- (void)hh_presentTiltedVC:(UIViewController *)controller completion:(void (^__nullable)(void))completion;
- (void)hh_presentCircleVC:(UIViewController *)controller point:(CGPoint)point completion:(void (^__nullable)(void))completion;

/**
垂直折叠式
End circular enlargement transition, Need to pass the param `touch point`
@param controller 控制器
@param completion 回调函数
*/
- (void)hh_presentErectVC:(UIViewController * _Nonnull)controller completion:(void (^__nullable)(void))completion;

/**
圆形放大式自定义结束触摸点
@param point 触摸点
@param completion 回调函数
*/
- (void)hh_dismissWithPoint:(CGPoint)point completion:(void (^__nullable)(void))completion;

/**
pushScale转场控制器重写
AnimationStyleScale transition must need to override
@return 转场视图
*/
- (UIView *_Nonnull)hh_transitionAnimationView;//need to override

Expand All @@ -73,10 +49,9 @@ NS_ASSUME_NONNULL_BEGIN
@interface UINavigationController (HHPush)

/**
CATransitin转场动画
NavigationController transition, Partial style available
detail in "AnimationStyle.h"
@param viewController 转场控制器
@param style 转场类型
*/
- (void)hh_pushViewController:(UIViewController *)viewController style:(AnimationStyle)style;

Expand Down
23 changes: 9 additions & 14 deletions HHTransition/UIViewController+HHTransition.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@

@interface UIViewController ()

@property (nonatomic, assign) AnimationStyle animationStyle;
@property (nonatomic, strong) VCTransitionDelegate *transitionDelegate;
@property (nonatomic, strong) VCInteractionDelegate *interactionDelegate;
@end

@end

@implementation UIViewController (HHPresent)

Expand Down Expand Up @@ -77,26 +78,18 @@ - (VCInteractionDelegate *)interactionDelegate
return objc_getAssociatedObject(self, interactionDelegateKey);
}

- (void)hh_presentBackScaleVC:(UIViewController *)controller height:(CGFloat)height completion:(void (^)(void))completion
{
[self hh_presentVC:controller type:AnimationStyleBackScale height:height point:CGPointZero completion:completion];
}
- (void)hh_presentCircleVC:(UIViewController *)controller point:(CGPoint)point completion:(void (^)(void))completion
{
[self hh_presentVC:controller type:AnimationStyleCircle height:0 point:point completion:completion];
[self hh_presentVC:controller type:AnimationStyleCircle point:point completion:completion];
}
- (void)hh_presentErectVC:(UIViewController *)controller completion:(void (^)(void))completion
{
[self hh_presentVC:controller type:AnimationStyleErect height:0 point:CGPointZero completion:completion];
}
- (void)hh_presentTiltedVC:(UIViewController *)controller completion:(void (^)(void))completion

- (void)hh_presentVC:(UIViewController *)controller type:(AnimationStyle)style completion:(void (^)(void))completion
{
[self hh_presentVC:controller type:AnimationStyleTilted height:0 point:CGPointZero completion:completion];
[self hh_presentVC:controller type:style point:CGPointZero completion:completion];
}
- (void)hh_presentVC:(UIViewController *)controller type:(AnimationStyle)style height:(CGFloat)height point:(CGPoint)point completion:(void (^)(void))completion
- (void)hh_presentVC:(UIViewController *)controller type:(AnimationStyle)style point:(CGPoint)point completion:(void (^)(void))completion
{
self.transitionDelegate = [VCTransitionDelegate new];
self.transitionDelegate.height = height;
self.transitionDelegate.touchPoint = point;
controller.animationStyle = style;
controller.modalPresentationStyle = UIModalPresentationCustom;
Expand Down Expand Up @@ -128,9 +121,11 @@ - (void)resetInitialInfo
self.view.layer.anchorPoint = CGPointMake(0.5, 0.5);
self.view.layer.frame = CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height);
}

- (UIView *)hh_transitionAnimationView{
return nil;
}

@end


Expand Down
1 change: 0 additions & 1 deletion HHTransition/VCTransitionDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

@interface VCTransitionDelegate : NSObject<UIViewControllerTransitioningDelegate>

@property (nonatomic, assign) CGFloat height;
@property (nonatomic, assign) CGPoint touchPoint;

@end
4 changes: 2 additions & 2 deletions HHTransition/VCTransitionDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ @implementation VCTransitionDelegate
id<UIViewControllerAnimatedTransitioning> objc = nil;
switch (presented.animationStyle) {
case AnimationStyleBackScale:
objc = [AnimationFadeBegin animationHeight:_height];
objc = [AnimationFadeBegin new];
break;
case AnimationStyleCircle:
objc = [AnimationWaveBegin animationOrigin:_touchPoint];
Expand All @@ -46,7 +46,7 @@ @implementation VCTransitionDelegate
id<UIViewControllerAnimatedTransitioning> objc = nil;
switch (dismissed.animationStyle) {
case AnimationStyleBackScale:
objc = [AnimationFadeEnd animationHeight:_height];
objc = [AnimationFadeEnd new];
break;
case AnimationStyleCircle:
objc = [AnimationWaveEnd animationOrigin:_touchPoint];
Expand Down
28 changes: 19 additions & 9 deletions HHTransitionDemo/BackScaleViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@

@interface BackScaleViewController ()

@property (nonatomic, strong) UIView *testView;
@property (nonatomic, strong) UIView *topView;
@property (nonatomic, strong) UIView *bottomView;

@end

Expand All @@ -22,18 +21,29 @@ @implementation BackScaleViewController
- (void)viewDidLoad {
[super viewDidLoad];

self.view.backgroundColor = [UIColor redColor];
self.view.backgroundColor = [UIColor clearColor];

_bottomView = [[UIView alloc] initWithFrame:CGRectMake(0, [UIScreen mainScreen].bounds.size.height, [UIScreen mainScreen].bounds.size.width, 400)];
_bottomView.backgroundColor = [UIColor redColor];
[self.view addSubview:_bottomView];

UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(buttonClick)];
[self.view addGestureRecognizer:tapGesture];
}

UIButton *button = [UIButton new];
button.frame = CGRectMake(0, 0, 40, 40);
[button setTitle:@"关闭" forState:UIControlStateNormal];
[button setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
[self.view addSubview:button];
[button addTarget:self action:@selector(buttonClick) forControlEvents:UIControlEventTouchUpInside];
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[UIView animateWithDuration:0.4 animations:^{
self.bottomView.y = [UIScreen mainScreen].bounds.size.height-self.bottomView.height;
}];
}

- (void)buttonClick
{
[UIView animateWithDuration:0.4 animations:^{
self.bottomView.y = [UIScreen mainScreen].bounds.size.height;
}];
[self dismissViewControllerAnimated:YES completion:nil];
}

Expand Down
1 change: 0 additions & 1 deletion HHTransitionDemo/ViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,5 @@

@interface ViewController : UIViewController


@end

8 changes: 4 additions & 4 deletions HHTransitionDemo/ViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -157,19 +157,19 @@ - (void)circleButtonClick:(UIButton *)sender
[self hh_presentCircleVC:circleVC point:_touchPoint completion:nil];
}
break;
case 1:
[self hh_presentBackScaleVC:[BackScaleViewController new] height:400 completion:nil];
case 1://内部只做背部控制器动画,前台动画自己控制
[self hh_presentVC:[BackScaleViewController new] type:AnimationStyleBackScale completion:nil];
break;
case 2:{
CircleViewController *circleVC = [CircleViewController new];
circleVC.isNeedShow = YES;
[self.navigationController hh_presentErectVC:circleVC completion:nil];
[self hh_presentVC:circleVC type:AnimationStyleErect completion:nil];
}
break;
case 3:{
CircleViewController *circleVC = [CircleViewController new];
circleVC.isNeedShow = YES;
[self.navigationController hh_presentTiltedVC:circleVC completion:nil];
[self hh_presentVC:circleVC type:AnimationStyleTilted completion:nil];
}
break;
case 4:{
Expand Down
Loading

0 comments on commit 341f482

Please sign in to comment.