Skip to content

Commit

Permalink
解决无法多次push和present的问题,统一枚举类型
Browse files Browse the repository at this point in the history
  • Loading branch information
yuwind committed Jun 1, 2018
1 parent a4de0fd commit f833e76
Show file tree
Hide file tree
Showing 14 changed files with 207 additions and 169 deletions.
28 changes: 28 additions & 0 deletions HHTransition/AnimationStyle.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
//
// AnimationStyle.h
// https://github.com/yuwind/HHTransition
//
// Created by 豫风 on 2018/6/1.
// Copyright © 2018年 豫风. All rights reserved.
//

#ifndef AnimationStyle_h
#define AnimationStyle_h

typedef enum : NSUInteger{
AnimationStyleNone = 0,
AnimationStyleCircle,//for present
AnimationStyleBackScale,//for present
AnimationStyleErect,//common
AnimationStyleTilted,//common
AnimationStyleScale,//for push
AnimationStyleBack,//for push
AnimationStyleCube,//for push
AnimationStyleSuckEffect,//for push
AnimationStyleOglFlip,//for push
AnimationStyleRippleEffect,//for push
AnimationStylePageCurl,//for push
AnimationStyleCameralIrisHollowOpen,//for push
} AnimationStyle;

#endif /* AnimationStyle_h */
3 changes: 2 additions & 1 deletion HHTransition/AnimationTildEnd.m
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,12 @@ -(void)animateTransition:(id<UIViewControllerContextTransitioning>)transitionCon
snapShot.layer.anchorPoint = CGPointMake(0.5, 1.5);
snapShot.layer.position = CGPointMake(snapShot.bounds.size.width * 0.5, snapShot.bounds.size.height * 1.5);
snapShot.transform = CGAffineTransformIdentity;

fromView.hidden = YES;
[UIView animateWithDuration:0.3 animations:^{
snapShot.transform = CGAffineTransformMakeRotation(M_PI_4);
} completion:^(BOOL finished) {

fromView.hidden = NO;
[snapShot removeFromSuperview];
[transitionContext completeTransition:!transitionContext.transitionWasCancelled];
}];
Expand Down
6 changes: 3 additions & 3 deletions HHTransition/AnimationTransitionBegin.h
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
//
// AnimationTransition.h
// HHTransitionDemo
// https://github.com/yuwind/HHTransition
//
// Created by 豫风 on 2018/5/17.
// Copyright © 2018年 豫风. All rights reserved.
//

#import <UIKit/UIKit.h>
#import "VCInteractionDelegate.h"
#import "AnimationStyle.h"

@interface AnimationTransitionBegin : NSObject<UIViewControllerAnimatedTransitioning>

+ (instancetype)animationStyle:(InteractionStyle)style;
+ (instancetype)animationStyle:(AnimationStyle)style;

@end
18 changes: 9 additions & 9 deletions HHTransition/AnimationTransitionBegin.m
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//
// AnimationTransition.m
// HHTransitionDemo
// https://github.com/yuwind/HHTransition
//
// Created by 豫风 on 2018/5/17.
// Copyright © 2018年 豫风. All rights reserved.
Expand All @@ -11,13 +11,13 @@

@interface AnimationTransitionBegin()<CAAnimationDelegate>

@property (nonatomic, assign) InteractionStyle style;
@property (nonatomic, assign) AnimationStyle style;
@property (nonatomic, strong) id<UIViewControllerContextTransitioning>transitionContext;

@end
@implementation AnimationTransitionBegin

+ (instancetype)animationStyle:(InteractionStyle)style
+ (instancetype)animationStyle:(AnimationStyle)style
{
AnimationTransitionBegin *animation = [AnimationTransitionBegin new];
animation.style = style;
Expand All @@ -41,30 +41,30 @@ - (void)animateTransition:(id<UIViewControllerContextTransitioning>)transitionCo
animation.duration = [self transitionDuration:transitionContext];
animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];
switch (_style) {
case TransitonStyleCube:{
case AnimationStyleCube:{
animation.type = @"cube";
animation.subtype = kCATransitionFromRight;
}
break;
case TransitonStyleSuckEffect:{
case AnimationStyleSuckEffect:{
animation.type = @"suckEffect";
}
break;
case TransitonStyleOglFlip:{
case AnimationStyleOglFlip:{
animation.type = @"oglFlip";
animation.subtype = kCATransitionFromLeft;
}
break;
case TransitonStyleRippleEffect:{
case AnimationStyleRippleEffect:{
animation.type = @"rippleEffect";
}
break;
case TransitonStylePageCurl:{
case AnimationStylePageCurl:{
animation.type = @"pageUnCurl";
animation.subtype = kCATransitionFromLeft;
}
break;
case TransitonStyleCameralIrisHollowOpen:{
case AnimationStyleCameralIrisHollowOpen:{
animation.type = @"cameralIrisHollowOpen";
animation.subtype = kCATransitionFromLeft;
}
Expand Down
6 changes: 3 additions & 3 deletions HHTransition/AnimationTransitionEnd.h
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
//
// AnimationTransitionEnd.h
// HHTransitionDemo
// https://github.com/yuwind/HHTransition
//
// Created by 豫风 on 2018/5/17.
// Copyright © 2018年 豫风. All rights reserved.
//

#import <UIKit/UIKit.h>
#import "VCInteractionDelegate.h"
#import "AnimationStyle.h"

@interface AnimationTransitionEnd : NSObject<UIViewControllerAnimatedTransitioning>

+ (instancetype)animationStyle:(InteractionStyle)style;
+ (instancetype)animationStyle:(AnimationStyle)style;

@end
18 changes: 9 additions & 9 deletions HHTransition/AnimationTransitionEnd.m
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//
// AnimationTransitionEnd.m
// HHTransitionDemo
// https://github.com/yuwind/HHTransition
//
// Created by 豫风 on 2018/5/17.
// Copyright © 2018年 豫风. All rights reserved.
Expand All @@ -10,14 +10,14 @@

@interface AnimationTransitionEnd()<CAAnimationDelegate>

@property (nonatomic, assign) InteractionStyle style;
@property (nonatomic, assign) AnimationStyle style;
@property (nonatomic, strong) id<UIViewControllerContextTransitioning>transitionContext;

@end

@implementation AnimationTransitionEnd

+ (instancetype)animationStyle:(InteractionStyle)style
+ (instancetype)animationStyle:(AnimationStyle)style
{
AnimationTransitionEnd *animation = [AnimationTransitionEnd new];
animation.style = style;
Expand All @@ -41,30 +41,30 @@ - (void)animateTransition:(id<UIViewControllerContextTransitioning>)transitionCo
animation.duration = [self transitionDuration:transitionContext];
animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];
switch (_style) {
case TransitonStyleCube:{
case AnimationStyleCube:{
animation.type = @"cube";
animation.subtype = kCATransitionFromLeft;
}
break;
case TransitonStyleSuckEffect:{
case AnimationStyleSuckEffect:{
animation.type = @"suckEffect";
}
break;
case TransitonStyleOglFlip:{
case AnimationStyleOglFlip:{
animation.type = @"oglFlip";
animation.subtype = kCATransitionFromRight;
}
break;
case TransitonStyleRippleEffect:{
case AnimationStyleRippleEffect:{
animation.type = @"rippleEffect";
}
break;
case TransitonStylePageCurl:{
case AnimationStylePageCurl:{
animation.type = @"pageCurl";
animation.subtype = kCATransitionFromLeft;
}
break;
case TransitonStyleCameralIrisHollowOpen:{
case AnimationStyleCameralIrisHollowOpen:{
animation.type = @"cameralIrisHollowOpen";
}
break;
Expand Down
35 changes: 19 additions & 16 deletions HHTransition/UIViewController+HHTransition.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,12 @@

#import <UIKit/UIKit.h>
#import "UIView+HHConstraint.h"
#import "AnimationStyle.h"

@interface UIViewController (HHPresent)

@property (nonatomic, assign) AnimationStyle animationStyle;

/**
背部缩隐式
Expand All @@ -29,6 +32,14 @@
*/
- (void)hh_presentCircleVC:(UIViewController * _Nonnull)controller point:(CGPoint)point completion:(void (^ __nullable)(void))completion;

/**
旋转样式
@param controller 控制器
@param completion 回调函数
*/
- (void)hh_presentTiltedVC:(UIViewController * _Nonnull)controller completion:(void (^ __nullable)(void))completion;

/**
垂直折叠式
Expand All @@ -54,18 +65,17 @@

@end

typedef enum : NSUInteger {
SysTransitonStyleCube = 4,
SysTransitonStyleSuckEffect,
SysTransitonStyleOglFlip,
SysTransitonStyleRippleEffect,
SysTransitonStylePageCurl,
SysTransitonStyleCameralIrisHollowOpen,
} SysTransitonStyle;


@interface UINavigationController (HHPush)

/**
CATransitin转场动画
@param viewController 转场控制器
@param style 转场类型
*/
- (void)hh_pushViewController:(UIViewController * _Nonnull)viewController style:(AnimationStyle)style;

/**
连续转场动画,需要实现方法`hh_transitionAnimationView`传递视图
Expand Down Expand Up @@ -94,12 +104,5 @@ typedef enum : NSUInteger {
*/
- (void)hh_pushBackViewController:(UIViewController * _Nonnull)viewController;

/**
CATransitin转场动画
@param viewController 转场控制器
@param style 转场类型
*/
- (void)hh_pushViewController:(UIViewController * _Nonnull)viewController sysStyle:(SysTransitonStyle)style;

@end
52 changes: 34 additions & 18 deletions HHTransition/UIViewController+HHTransition.m
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@


static char * const transitionDelegateKey = "transitionDelegateKey";
static char * const animationStyleKey = "animationStyleKey";

@interface UIViewController ()

Expand Down Expand Up @@ -49,6 +50,15 @@ + (void)load
}
}

- (void)setAnimationStyle:(AnimationStyle)animationStyle
{
objc_setAssociatedObject(self, animationStyleKey, @(animationStyle), OBJC_ASSOCIATION_ASSIGN);
}
- (AnimationStyle)animationStyle
{
return [objc_getAssociatedObject(self, animationStyleKey) integerValue];
}

- (void)setTransitionDelegate:(VCTransitionDelegate *)transitionDelegate
{
objc_setAssociatedObject(self, transitionDelegateKey, transitionDelegate, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
Expand All @@ -60,21 +70,26 @@ - (VCTransitionDelegate *)transitionDelegate

- (void)hh_presentBackScaleVC:(UIViewController *)controller height:(CGFloat)height completion:(void (^)(void))completion
{
[self hh_presentVC:controller type:TransitionStyleBackScale height:height point:CGPointZero completion: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:TransitionStyleCircle height:0 point:point completion:completion];
[self hh_presentVC:controller type:AnimationStyleCircle height:0 point:point completion:completion];
}
- (void)hh_presentErectVC:(UIViewController * _Nonnull)controller completion:(void (^ __nullable)(void))completion
- (void)hh_presentErectVC:(UIViewController * _Nonnull)controller completion:(void (^)(void))completion
{
[self hh_presentVC:controller type:TransitionStyleErect height:0 point:CGPointZero completion:completion];
[self hh_presentVC:controller type:AnimationStyleErect height:0 point:CGPointZero completion:completion];
}
- (void)hh_presentVC:(UIViewController *)controller type:(TransitionStyle)style height:(CGFloat)height point:(CGPoint)point completion:(void (^)(void))completion
- (void)hh_presentTiltedVC:(UIViewController * _Nonnull)controller completion:(void (^ __nullable)(void))completion
{
self.transitionDelegate = [VCTransitionDelegate transitionStyle:style];
[self hh_presentVC:controller type:AnimationStyleTilted height:0 point:CGPointZero completion:completion];
}
- (void)hh_presentVC:(UIViewController *)controller type:(AnimationStyle)style height:(CGFloat)height point:(CGPoint)point completion:(void (^)(void))completion
{
self.transitionDelegate = [VCTransitionDelegate shareInstance];
self.transitionDelegate.height = height;
self.transitionDelegate.touchPoint = point;
controller.animationStyle = style;
controller.modalPresentationStyle = UIModalPresentationCustom;
controller.transitioningDelegate = self.transitionDelegate;

Expand Down Expand Up @@ -134,33 +149,34 @@ - (VCInteractionDelegate *)interactionDelegate

- (void)hh_pushScaleViewController:(UIViewController *)viewController
{
[self hh_pushViewController:viewController style:InteractionStyleScale];
[self hh_pushViewController:viewController style:AnimationStyleScale];
}
- (void)hh_pushTiltViewController:(UIViewController *)viewController
{
[self hh_pushViewController:viewController style:InteractionStyleTilted];
[self hh_pushViewController:viewController style:AnimationStyleTilted];
}
- (void)hh_pushErectViewController:(UIViewController *)viewController
{
[self hh_pushViewController:viewController style:InteractionStyleErect];
[self hh_pushViewController:viewController style:AnimationStyleErect];
}
- (void)hh_pushBackViewController:(UIViewController *)viewController
{
[self hh_pushViewController:viewController style:InteractionStyleBack];
}
- (void)hh_pushViewController:(UIViewController * _Nonnull)viewController sysStyle:(SysTransitonStyle)style
{
[self hh_pushViewController:viewController style:(InteractionStyle)style];
[self hh_pushViewController:viewController style:AnimationStyleBack];
}
- (void)hh_pushViewController:(UIViewController *)viewController style:(InteractionStyle)style

- (void)hh_pushViewController:(UIViewController *)viewController style:(AnimationStyle)style
{
self.interactionDelegate = [VCInteractionDelegate interactionStyle:style];
self.interactionDelegate = [VCInteractionDelegate shareInstance];
self.interactionDelegate.navigation = self;
viewController.animationStyle = style;
UIScreenEdgePanGestureRecognizer *edgePan = [[UIScreenEdgePanGestureRecognizer alloc]initWithTarget:self.interactionDelegate action:NSSelectorFromString(@"edgePanAction:")];
edgePan.edges = UIRectEdgeLeft;
[viewController.view addGestureRecognizer:edgePan];
self.interactionDelegate.delegate = self.delegate?:nil;
self.delegate = self.interactionDelegate;
if (self.delegate != self.interactionDelegate) {

self.interactionDelegate.delegate = self.delegate?:nil;
self.delegate = self.interactionDelegate;
}
[self pushViewController:viewController animated:YES];
}

Expand Down
Loading

0 comments on commit f833e76

Please sign in to comment.