Commit c61fc9df authored by 汪洋's avatar 汪洋

使用最新的GMNavigationController

parent f73bc1dd
......@@ -88,7 +88,7 @@ EXTERNAL SOURCES:
SPEC CHECKSUMS:
AFNetworking: 5e0e199f73d8626b11e79750991f5d173d1f8b67
GMBase: 1654a1e7146647d619e536f3ecb97e6a37b83f91
GMBase: 92c86f8cac670ad053f26180f4458b730058d74a
GMCache: fb0af70b420715ef9519487fdd932a357b3cd8d4
GMHud: 74387462a8b9f099c760a1ddbf493cc86da7cdbc
GMKit: 4820e0eb7727735f88fb2f983f178edd074343c1
......
......@@ -2,7 +2,7 @@ Pod::Spec.new do |s|
s.name = 'GMBase'
s.version = '0.3.0'
s.summary = '更美iOS APP 的 Objective-C 基础Pod库'
s.homepage = 'http://git.gengmei.cc/gengmeiios/GMBase'
s.homepage = 'http://git.wanmeizhensuo.com/gengmeiios/GMBase'
s.license = '仅限北京更美互动信息科技有限公司内部使用'
s.author = { 'wangyang' => 'wangyang@gmei.com' }
s.source = { :git => 'git@git.wanmeizhensuo.com:gengmeiios/GMBase.git', :tag => s.version.to_s }
......
//
// GMNavigationController.h
// Gengmei
//
// Created by Terminator on 2017/8/30.
// Copyright © 2017年 更美互动信息科技有限公司. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface GMNavigationController : UINavigationController
@property (nonatomic, assign) BOOL needPopPresetAnimation;
@end
//
// GMNavigationController.m
// Gengmei
//
// Created by Terminator on 2017/8/30.
// Copyright © 2017年 更美互动信息科技有限公司. All rights reserved.
//
#import "GMNavigationController.h"
#import "UIViewController+PushType.h"
#import "GMPresentAnimation.h"
@import GMKit;
@interface GMNavigationController ()<UINavigationControllerDelegate>
@end
@implementation GMNavigationController
- (void)viewDidLoad {
[super viewDidLoad];
self.delegate = self;
self.fd_viewControllerBasedNavigationBarAppearanceEnabled = NO;
}
- (nullable id <UIViewControllerAnimatedTransitioning>)navigationController:(UINavigationController *)navigationController
animationControllerForOperation:(UINavigationControllerOperation)operation
fromViewController:(UIViewController *)fromVC
toViewController:(UIViewController *)toVC {
if (operation == UINavigationControllerOperationPush && toVC.isPresent) {
GMPresentAnimation *animation = [[GMPresentAnimation alloc] init];
animation.transitionType = operation;
return animation;
} else if (operation == UINavigationControllerOperationPop && (fromVC.isPresent || self.needPopPresetAnimation)) {
_needPopPresetAnimation = NO;
GMPresentAnimation *animation = [[GMPresentAnimation alloc] init];
animation.transitionType = operation;
return animation;
}
return nil;
}
@end
//
// GMPresentAnimation.h
// Gengmei
//
// Created by Terminator on 2017/8/30.
// Copyright © 2017年 更美互动信息科技有限公司. All rights reserved.
//
#import <Foundation/Foundation.h>
@interface GMPresentAnimation : NSObject<UIViewControllerAnimatedTransitioning>
@property(nonatomic,assign)UINavigationControllerOperation transitionType;
@end
//
// GMPresentAnimation.m
// Gengmei
//
// Created by Terminator on 2017/8/30.
// Copyright © 2017年 更美互动信息科技有限公司. All rights reserved.
//
#import "GMPresentAnimation.h"
#import "UIViewController+PushType.h"
@interface GMPresentAnimation() <UIViewControllerAnimatedTransitioning>
@property(nonatomic,assign)NSTimeInterval duration;
@end
@implementation GMPresentAnimation
- (instancetype)init
{
// 默认 push 动画时间0.6
if (self = [super init]) {
// self.duration = 0.6;
self.duration = 0.6;
}
return self;
}
- (void)push:(id<UIViewControllerContextTransitioning>)transitionContext
{
UIViewController *fromVC = [transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey];
UIViewController *toVC = [transitionContext viewControllerForKey:UITransitionContextToViewControllerKey];
NSTimeInterval duration = [self transitionDuration:transitionContext];
CGRect bound = [[UIScreen mainScreen] bounds];
fromVC.view.hidden = YES;
[[transitionContext containerView] addSubview:fromVC.snapshot];
[[transitionContext containerView] addSubview:toVC.view];
[[toVC.navigationController.view superview] insertSubview:fromVC.snapshot belowSubview:toVC.navigationController.view];
toVC.navigationController.view.layer.anchorPoint = CGPointMake(0.5, 2.0);
toVC.navigationController.view.frame = bound;
toVC.navigationController.view.transform = CGAffineTransformMakeTranslation(0, CGRectGetHeight(bound));
[UIView animateWithDuration:duration
delay:0
usingSpringWithDamping:1.0
initialSpringVelocity:0
options:UIViewAnimationOptionCurveLinear
animations:^{
fromVC.snapshot.transform = CGAffineTransformMakeTranslation(0, 0);
toVC.navigationController.view.transform = CGAffineTransformMakeTranslation(0, 0);
}
completion:^(BOOL finished) {
fromVC.view.hidden = NO;
[fromVC.snapshot removeFromSuperview];
[transitionContext completeTransition:YES];
}];
}
- (void)pop:(id<UIViewControllerContextTransitioning>)transitionContext
{
UIViewController * fromVC = [transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey];
UIViewController * toVC = [transitionContext viewControllerForKey:UITransitionContextToViewControllerKey];
NSTimeInterval duration = [self transitionDuration:transitionContext];
CGRect bound = [[UIScreen mainScreen] bounds];
[fromVC.view addSubview:fromVC.snapshot];
fromVC.navigationController.navigationBar.hidden = YES;
// 添加阴影
fromVC.snapshot.layer.shadowColor = [UIColor colorWithRed:0.2 green:0.2 blue:0.2 alpha:0.8].CGColor;
fromVC.snapshot.layer.shadowOffset = CGSizeMake(-3, 0);
fromVC.snapshot.layer.shadowOpacity = 0.5;
fromVC.view.layer.anchorPoint = CGPointMake(0.5, 2.5);
fromVC.view.frame = bound;
toVC.view.hidden = YES;
[[transitionContext containerView] addSubview:toVC.view];
[[transitionContext containerView] addSubview:toVC.snapshot];
[[transitionContext containerView] sendSubviewToBack:toVC.snapshot];
[UIView animateWithDuration:duration
delay:0
usingSpringWithDamping:1.0
initialSpringVelocity:0
options:UIViewAnimationOptionCurveLinear
animations:^{
fromVC.view.transform = CGAffineTransformMakeTranslation(0, CGRectGetHeight(bound));
toVC.snapshot.alpha = 1;
}
completion:^(BOOL finished) {
toVC.navigationController.navigationBar.hidden = NO;
toVC.view.hidden = NO;
[fromVC.snapshot removeFromSuperview];
[toVC.snapshot removeFromSuperview];
if (![transitionContext transitionWasCancelled])
{
toVC.snapshot = nil;
}
[transitionContext completeTransition:![transitionContext transitionWasCancelled]];
}];
}
- (NSTimeInterval)transitionDuration:(nullable id <UIViewControllerContextTransitioning>)transitionContext
{
return self.duration;
}
- (void)animateTransition:(id <UIViewControllerContextTransitioning>)transitionContext
{
if (self.transitionType == UINavigationControllerOperationPush)
{
[self push:transitionContext];
}
else if (self.transitionType == UINavigationControllerOperationPop)
{
[self pop:transitionContext];
}
}
@end
//
// UIViewController+NavigationCompletionBlock.h
// GMBase
//
// Created by wangyang on 2018/1/25.
//
#import <UIKit/UIKit.h>
NS_ASSUME_NONNULL_BEGIN
@interface UIViewController (NavigationCompletionBlock)
- (void)pushViewController:(UIViewController* _Nonnull)viewController
animated:(BOOL)animated
completion:(void (^ __nullable)(void))completion;
- (nullable UIViewController *)popViewControllerAnimated:(BOOL)animated
completion:(void (^ __nullable)(void))completion;
- (nullable NSArray<__kindof UIViewController *> *)popToViewController:(UIViewController * _Nonnull)viewController
animated:(BOOL)animated
completion: (void (^ __nullable)(void))completion;
- (nullable NSArray<__kindof UIViewController *> *)popToRootViewControllerAnimated:(BOOL)animated
completion: (void (^ __nullable)(void))completion;
- (void)pushAndKillToRoot:(UIViewController *)controller;
/**
push动画完成后删除navigation中controller与controllerClass之间的controllers。
注意:controllerClass如果有多个只使用离controller最近那个
*/
- (void)push:(UIViewController *)controller andKillTo:(Class)controllerClass;
@end
NS_ASSUME_NONNULL_END
//
// UIViewController+NavigationCompletionBlock.m
// GMBase
//
// Created by wangyang on 2018/1/25.
//
#import "UIViewController+NavigationCompletionBlock.h"
@implementation UIViewController (NavigationCompletionBlock)
- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated completion: (void (^ __nullable)(void))completion {
[CATransaction setCompletionBlock:completion];
[CATransaction begin];
[self.navigationController pushViewController:viewController animated:animated];
[CATransaction commit];
}
- (nullable UIViewController *)popViewControllerAnimated:(BOOL)animated completion: (void (^ __nullable)(void))completion {
UIViewController *poppedViewController;
[CATransaction setCompletionBlock:completion];
[CATransaction begin];
poppedViewController = [self.navigationController popViewControllerAnimated:animated];
[CATransaction commit];
return poppedViewController;
}
- (nullable NSArray<__kindof UIViewController *> *)popToViewController:(UIViewController * _Nonnull)viewController animated:(BOOL)animated completion: (void (^ __nullable)(void))completion{
NSArray<UIViewController*>* viewControllers;
[CATransaction setCompletionBlock:completion];
[CATransaction begin];
viewControllers = [self.navigationController popToViewController:viewController animated:animated];
[CATransaction commit];
return viewControllers;
}
- (nullable NSArray<__kindof UIViewController *> *)popToRootViewControllerAnimated:(BOOL)animated completion: (void (^ __nullable)(void))completion {
NSArray<UIViewController*>* viewControllers;
[CATransaction setCompletionBlock:completion];
[CATransaction begin];
viewControllers = [self.navigationController popToRootViewControllerAnimated:animated];
[CATransaction commit];
return viewControllers;
}
- (void)pushAndKillToRoot:(UIViewController *)controller {
NSMutableArray *result = [self.navigationController.viewControllers mutableCopy];
do {
[result removeLastObject];
} while (result.count != 1);
[CATransaction setCompletionBlock:^{
[result addObject:controller];
self.navigationController.viewControllers = result;
}];
[CATransaction begin];
[self.navigationController pushViewController:controller animated:YES];
[CATransaction commit];
}
/**
push动画完成后删除navigation中controller与controllerClass之间的controllers。
注意:controllerClass如果有多个只使用离controller最近那个
*/
- (void)push:(UIViewController *)controller andKillTo:(Class)controllerClass {
NSMutableArray *result = [self.navigationController.viewControllers mutableCopy];
do {
[result removeLastObject];
} while (![result.lastObject isMemberOfClass:controllerClass]);
[CATransaction setCompletionBlock:^{
[result addObject:controller];
self.navigationController.viewControllers = result;
}];
[CATransaction begin];
[self.navigationController pushViewController:controller animated:YES];
[CATransaction commit];
}
@end
//
// UIViewController+PushType.h
// Gengmei
//
// Created by Terminator on 2017/8/30.
// Copyright © 2017年 更美互动信息科技有限公司. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface UIViewController (Push)
@property (nonatomic, strong) UIView *snapshot;
//push type是否是模态动画
@property (nonatomic, assign) BOOL isPresent;
- (void)popToPresentPreviousController;
@end
//
// UIViewController+PushType.m
// Gengmei
//
// Created by Terminator on 2017/8/30.
// Copyright © 2017年 更美互动信息科技有限公司. All rights reserved.
//
#import "UIViewController+PushType.h"
#import <objc/runtime.h>
#import "GMNavigationController.h"
@implementation UIViewController (PushType)
- (UIView *)snapshot
{
UIView *view = objc_getAssociatedObject(self, @"gmSnapshot");
if (!view) {
view = [self.navigationController.view snapshotViewAfterScreenUpdates:NO];
[self setSnapshot:view];
}
return view;
}
- (void)setSnapshot:(UIView *)snapshot
{
objc_setAssociatedObject(self, @"gmSnapshot", snapshot, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}
- (BOOL)isPresent {
return [objc_getAssociatedObject(self, @"gmIsPresent") boolValue];
}
-(void)setIsPresent:(BOOL)isPresent {
objc_setAssociatedObject(self, @"gmIsPresent", [NSNumber numberWithBool:isPresent], OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}
- (void)popToPresentPreviousController {
for (int index = 0; index < self.navigationController.viewControllers.count; index++) {
UIViewController *controller = self.navigationController.viewControllers[index];
if (controller.isPresent) {
GMNavigationController *nav = (GMNavigationController *)self.navigationController;
nav.needPopPresetAnimation = YES;
UIViewController *previewController = self.navigationController.viewControllers[index - 1];
[controller.navigationController popToViewController:previewController animated:YES];
return;
}
}
}
@end
//
// WMNavigationController.h
// Gengmei
//
// Created by wangyang on 1/16/15.
// Copyright (c) 2015 Wanmeichuangyi. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface WMNavigationController : UINavigationController
@end
//
// WMNavigationController.m
// Gengmei
//
// Created by wangyang on 1/16/15.
// Copyright (c) 2015 Wanmeichuangyi. All rights reserved.
//
#import "WMNavigationController.h"
@implementation WMNavigationController
- (void)viewDidLoad
{
[super viewDidLoad];
self.navigationBarHidden = YES;
self.view.backgroundColor = [UIColor whiteColor];
}
@end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment