diff --git a/GKNavigationBar.podspec b/GKNavigationBar.podspec index 7627cf6..c9c9049 100644 --- a/GKNavigationBar.podspec +++ b/GKNavigationBar.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = 'GKNavigationBar' - s.version = '1.8.2' + s.version = '1.8.3' s.license = 'MIT' s.summary = '自定义导航栏--导航栏联动' s.homepage = 'https://github.com/QuintGao/GKNavigationBar' diff --git a/GKNavigationBar/GestureHandle/GKGestureHandleConfigure.h b/GKNavigationBar/GestureHandle/GKGestureHandleConfigure.h index a4d5198..cd41b91 100644 --- a/GKNavigationBar/GestureHandle/GKGestureHandleConfigure.h +++ b/GKNavigationBar/GestureHandle/GKGestureHandleConfigure.h @@ -27,11 +27,7 @@ NS_ASSUME_NONNULL_BEGIN /// 右滑pop过渡临界值,默认0.5,大于此值完成pop操作 @property (nonatomic, assign) CGFloat gk_popTransitionCriticalValue; -// 以下属性需要设置导航栏转场缩放为YES -/// 手机系统大于11.0,使用下面的值控制x、y轴的位移距离,默认(5,5) -@property (nonatomic, assign) CGFloat gk_translationX; -@property (nonatomic, assign) CGFloat gk_translationY; -/// 手机系统小于11.0,使用下面的值控制x、y周的缩放程度,默认(0.95,0.97) +/// 控制x、y轴的缩放程度,默认(0.95,0.97) @property (nonatomic, assign) CGFloat gk_scaleX; @property (nonatomic, assign) CGFloat gk_scaleY; diff --git a/GKNavigationBar/GestureHandle/GKGestureHandleConfigure.m b/GKNavigationBar/GestureHandle/GKGestureHandleConfigure.m index c8ca1f8..5524774 100644 --- a/GKNavigationBar/GestureHandle/GKGestureHandleConfigure.m +++ b/GKNavigationBar/GestureHandle/GKGestureHandleConfigure.m @@ -36,8 +36,6 @@ - (void)setupDefaultConfigure { self.gk_pushTransitionCriticalValue = 0.3f; self.gk_popTransitionCriticalValue = 0.5f; - self.gk_translationX = 5.0f; - self.gk_translationY = 5.0f; self.gk_scaleX = 0.95f; self.gk_scaleY = 0.97f; } @@ -57,7 +55,7 @@ - (BOOL)isVelocityInSensitivity:(CGFloat)velocity { } - (UIImage *)getCaptureWithView:(UIView *)view { - UIGraphicsBeginImageContextWithOptions(view.bounds.size, view.opaque, 0); + UIGraphicsBeginImageContextWithOptions(view.bounds.size, NO, UIScreen.mainScreen.scale); [view drawViewHierarchyInRect:view.bounds afterScreenUpdates:NO]; UIImage *image = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); diff --git a/GKNavigationBar/GestureHandle/GKPopAnimatedTransition.m b/GKNavigationBar/GestureHandle/GKPopAnimatedTransition.m index b28c453..1b7f247 100644 --- a/GKNavigationBar/GestureHandle/GKPopAnimatedTransition.m +++ b/GKNavigationBar/GestureHandle/GKPopAnimatedTransition.m @@ -12,45 +12,43 @@ @implementation GKPopAnimatedTransition - (void)animateTransition { - [self.containerView insertSubview:self.toViewController.view belowSubview:self.fromViewController.view]; - // 是否隐藏tabBar self.isHideTabBar = self.toViewController.tabBarController && self.fromViewController.hidesBottomBarWhenPushed && self.toViewController.gk_captureImage; + if (self.toViewController.navigationController.childViewControllers.firstObject != self.toViewController) { + self.isHideTabBar = NO; + } + UITabBar *tabBar = self.toViewController.tabBarController.tabBar; CGFloat screenW = self.containerView.bounds.size.width; CGFloat screenH = self.containerView.bounds.size.height; - __block UIView *toView = nil; + __block UIView *toView = [[UIView alloc] initWithFrame:self.containerView.bounds]; + __block UIView *captureView = nil; + + [toView addSubview:self.toViewController.view]; + if (self.isHideTabBar) { - UIImageView *captureView = [[UIImageView alloc] initWithImage:self.toViewController.gk_captureImage]; - captureView.frame = CGRectMake(0, 0, screenW, screenH); - [self.containerView insertSubview:captureView belowSubview:self.fromViewController.view]; - toView = captureView; - self.toViewController.view.hidden = YES; - self.toViewController.tabBarController.tabBar.hidden = YES; - }else { - toView = self.toViewController.view; + captureView = [[UIImageView alloc] initWithImage:self.toViewController.gk_captureImage]; + CGRect frame = tabBar.frame; + frame.origin.x = 0; + captureView.frame = frame; + [toView addSubview:captureView]; + tabBar.hidden = YES; } - self.contentView = toView; if (self.isScale) { self.shadowView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, screenW, screenH)]; self.shadowView.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.6f]; [toView addSubview:self.shadowView]; - - if (@available(iOS 11.0, *)) { - CGRect frame = toView.frame; - frame.origin.x = GKGestureConfigure.gk_translationX; - frame.origin.y = GKGestureConfigure.gk_translationY; - frame.size.height -= 2 * GKGestureConfigure.gk_translationY; - toView.frame = frame; - }else { - toView.transform = CGAffineTransformMakeScale(GKGestureConfigure.gk_scaleX, GKGestureConfigure.gk_scaleY); - } + toView.transform = CGAffineTransformMakeScale(GKGestureConfigure.gk_scaleX, GKGestureConfigure.gk_scaleY); }else { - toView.frame = CGRectMake(- (0.3 * screenW), 0, screenW, screenH); + CGRect frame = toView.frame; + frame.origin.x = -0.3 * frame.size.width; + toView.frame = frame; } + [self.containerView insertSubview:toView belowSubview:self.fromViewController.view]; + self.fromViewController.view.layer.shadowColor = [UIColor blackColor].CGColor; self.fromViewController.view.layer.shadowOpacity = 0.15f; self.fromViewController.view.layer.shadowRadius = 3.0f; @@ -59,28 +57,39 @@ - (void)animateTransition { self.fromViewController.view.frame = CGRectMake(screenW, 0, screenW, screenH); if (self.isScale) { self.shadowView.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0]; - if (@available(iOS 11.0, *)) { - toView.frame = CGRectMake(0, 0, screenW, screenH); - }else { - toView.transform = CGAffineTransformIdentity; - } + toView.transform = CGAffineTransformIdentity; }else { - toView.frame = CGRectMake(0, 0, screenW, screenH); + CGRect frame = toView.frame; + frame.origin.x = 0; + toView.frame = frame; } } completion:^(BOOL finished) { - [self completeTransition]; if (self.isHideTabBar) { - [self.contentView removeFromSuperview]; - self.contentView = nil; + self.toViewController.gk_captureImage = nil; + if (self.transitionContext.transitionWasCancelled) { + [self.toViewController.view removeFromSuperview]; + }else { + [self.containerView addSubview:self.toViewController.view]; + } + + toView.transform = CGAffineTransformIdentity; + if (toView) { + [toView removeFromSuperview]; + toView = nil; + } + if (captureView) { + [captureView removeFromSuperview]; + captureView = nil; + } - self.toViewController.view.hidden = NO; if (self.toViewController.navigationController.childViewControllers.count == 1) { - self.toViewController.tabBarController.tabBar.hidden = NO; + tabBar.hidden = NO; } } if (self.isScale) { [self.shadowView removeFromSuperview]; } + [self completeTransition]; }]; } diff --git a/GKNavigationBar/GestureHandle/GKPushAnimatedTransition.m b/GKNavigationBar/GestureHandle/GKPushAnimatedTransition.m index b2c3904..9113fba 100644 --- a/GKNavigationBar/GestureHandle/GKPushAnimatedTransition.m +++ b/GKNavigationBar/GestureHandle/GKPushAnimatedTransition.m @@ -14,31 +14,45 @@ @implementation GKPushAnimatedTransition - (void)animateTransition { // 解决UITabbarController左滑push时的显示问题 self.isHideTabBar = self.fromViewController.tabBarController && self.toViewController.hidesBottomBarWhenPushed; + + UITabBar *tabBar = self.fromViewController.tabBarController.tabBar; + // tabBar位置不对或隐藏 + if (tabBar.frame.origin.x != 0 || tabBar.isHidden) { + self.isHideTabBar = NO; + } + + // 非根控制器 + if (self.fromViewController.navigationController.childViewControllers.firstObject != self.fromViewController) { + self.isHideTabBar = NO; + } CGFloat screenW = self.containerView.bounds.size.width; CGFloat screenH = self.containerView.bounds.size.height; - __block UIView *fromView = nil; + __block UIView *fromView = [[UIView alloc] initWithFrame:self.containerView.bounds]; + [fromView addSubview:self.fromViewController.view]; + + __block UIView *captureView = nil; if (self.isHideTabBar) { - // 获取fromViewController的截图 - UIImage *captureImage = [GKGestureConfigure getCaptureWithView:self.fromViewController.view.window]; - UIImageView *captureView = [[UIImageView alloc] initWithImage:captureImage]; - captureView.frame = CGRectMake(0, 0, screenW, screenH); - [self.containerView addSubview:captureView]; - fromView = captureView; + // 截取tabBar + UIImage *captureImage = [GKGestureConfigure getCaptureWithView:tabBar]; + self.fromViewController.gk_captureImage = captureImage; - self.fromViewController.view.hidden = YES; - self.fromViewController.tabBarController.tabBar.hidden = YES; - }else { - fromView = self.fromViewController.view; + captureView = [[UIImageView alloc] initWithImage:captureImage]; + CGRect frame = tabBar.frame; + frame.origin.x = 0; + captureView.frame = frame; + [fromView addSubview:captureView]; + tabBar.hidden = YES; } - self.contentView = fromView; if (self.isScale) { self.shadowView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, screenW, screenH)]; self.shadowView.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0]; [fromView addSubview:self.shadowView]; + fromView.transform = CGAffineTransformIdentity; } + [self.containerView addSubview:fromView]; // 设置toViewController self.toViewController.view.frame = CGRectMake(screenW, 0, screenW, screenH); @@ -50,34 +64,36 @@ - (void)animateTransition { [UIView animateWithDuration:self.animationDuration animations:^{ if (self.isScale) { self.shadowView.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.6f]; - if (@available(iOS 11.0, *)) { - CGRect frame = fromView.frame; - frame.origin.x = GKGestureConfigure.gk_translationX; - frame.origin.y = GKGestureConfigure.gk_translationY; - frame.size.height -= 2 * GKGestureConfigure.gk_translationY; - fromView.frame = frame; - }else { - fromView.transform = CGAffineTransformMakeScale(GKGestureConfigure.gk_scaleX, GKGestureConfigure.gk_scaleY); - } + fromView.transform = CGAffineTransformMakeScale(GKGestureConfigure.gk_scaleX, GKGestureConfigure.gk_scaleY); }else { - fromView.frame = CGRectMake(- (0.3 * screenW), 0, screenW, screenH); + CGRect frame = fromView.frame; + frame.origin.x = -0.3 * frame.size.width; + fromView.frame = frame; } - self.toViewController.view.frame = CGRectMake(0, 0, screenW, screenH); } completion:^(BOOL finished) { - [self completeTransition]; if (self.isHideTabBar) { - [self.contentView removeFromSuperview]; - self.contentView = nil; - - self.fromViewController.view.hidden = NO; - if (self.fromViewController.navigationController.childViewControllers.count == 1) { - self.fromViewController.tabBarController.tabBar.hidden = NO; + if (self.transitionContext.transitionWasCancelled) { + [self.containerView addSubview:self.fromViewController.view]; + }else { + [self.fromViewController.view removeFromSuperview]; + } + + fromView.transform = CGAffineTransformIdentity; + if (fromView) { + [fromView removeFromSuperview]; + fromView = nil; + } + + if (captureView) { + [captureView removeFromSuperview]; + captureView = nil; } } if (self.isScale) { [self.shadowView removeFromSuperview]; } + [self completeTransition]; }]; } diff --git a/GKNavigationBarExample/GKNavigationBarExample.xcodeproj/project.pbxproj b/GKNavigationBarExample/GKNavigationBarExample.xcodeproj/project.pbxproj index 94f24c2..907a92f 100644 --- a/GKNavigationBarExample/GKNavigationBarExample.xcodeproj/project.pbxproj +++ b/GKNavigationBarExample/GKNavigationBarExample.xcodeproj/project.pbxproj @@ -884,9 +884,9 @@ buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CLANG_ENABLE_MODULES = YES; - CODE_SIGN_IDENTITY = "Apple Development: xinjun zhang (DNJGV7XB9Q)"; - CODE_SIGN_STYLE = Manual; - DEVELOPMENT_TEAM = X52753HQNM; + CODE_SIGN_IDENTITY = "Apple Development"; + CODE_SIGN_STYLE = Automatic; + DEVELOPMENT_TEAM = P756K496H9; GCC_PREFIX_HEADER = GKNavigationBarExample/PrefixHeader.pch; INFOPLIST_FILE = GKNavigationBarExample/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 9.0; @@ -896,7 +896,7 @@ ); PRODUCT_BUNDLE_IDENTIFIER = com.test.gknavigationbar; PRODUCT_NAME = "$(TARGET_NAME)"; - PROVISIONING_PROFILE_SPECIFIER = aystfm_dev_test; + PROVISIONING_PROFILE_SPECIFIER = ""; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; SWIFT_VERSION = 5.0; TARGETED_DEVICE_FAMILY = "1,2"; @@ -909,9 +909,9 @@ buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CLANG_ENABLE_MODULES = YES; - CODE_SIGN_IDENTITY = "Apple Development: xinjun zhang (DNJGV7XB9Q)"; - CODE_SIGN_STYLE = Manual; - DEVELOPMENT_TEAM = X52753HQNM; + CODE_SIGN_IDENTITY = "Apple Development"; + CODE_SIGN_STYLE = Automatic; + DEVELOPMENT_TEAM = P756K496H9; GCC_PREFIX_HEADER = GKNavigationBarExample/PrefixHeader.pch; INFOPLIST_FILE = GKNavigationBarExample/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 9.0; @@ -921,7 +921,7 @@ ); PRODUCT_BUNDLE_IDENTIFIER = com.test.gknavigationbar; PRODUCT_NAME = "$(TARGET_NAME)"; - PROVISIONING_PROFILE_SPECIFIER = aystfm_dev_test; + PROVISIONING_PROFILE_SPECIFIER = ""; SWIFT_VERSION = 5.0; TARGETED_DEVICE_FAMILY = "1,2"; }; diff --git a/GKNavigationBarExample/GKNavigationBarExample/AppDelegate.m b/GKNavigationBarExample/GKNavigationBarExample/AppDelegate.m index 7505e15..8667f80 100644 --- a/GKNavigationBarExample/GKNavigationBarExample/AppDelegate.m +++ b/GKNavigationBarExample/GKNavigationBarExample/AppDelegate.m @@ -50,8 +50,6 @@ - (void)setupNavBar { // 设置手势返回 [GKGestureConfigure setupCustomConfigure:^(GKGestureHandleConfigure * _Nonnull configure) { - configure.gk_translationX = 15; - configure.gk_translationY = 20; configure.gk_scaleX = 0.90; configure.gk_scaleY = 0.92; configure.gk_openScrollViewGestureHandle = YES; diff --git "a/GKNavigationBarExample/GKNavigationBarExample/Demo/\344\273\212\346\227\245\345\244\264\346\235\241/GKToutiaoViewController.m" "b/GKNavigationBarExample/GKNavigationBarExample/Demo/\344\273\212\346\227\245\345\244\264\346\235\241/GKToutiaoViewController.m" index 556a0fa..ec68a24 100644 --- "a/GKNavigationBarExample/GKNavigationBarExample/Demo/\344\273\212\346\227\245\345\244\264\346\235\241/GKToutiaoViewController.m" +++ "b/GKNavigationBarExample/GKNavigationBarExample/Demo/\344\273\212\346\227\245\345\244\264\346\235\241/GKToutiaoViewController.m" @@ -52,6 +52,7 @@ - (void)addChildVC:(UIViewController *)vc title:(NSString *)title imageName:(NSS vc.tabBarItem.titlePositionAdjustment = UIOffsetMake(0, -2); UINavigationController *nav = [UINavigationController rootVC:vc transitionScale:YES]; + nav.gk_openScrollLeftPush = YES; [self addChildViewController:nav]; } diff --git a/README.md b/README.md index 577cd25..a567e4d 100644 --- a/README.md +++ b/README.md @@ -202,6 +202,7 @@ github "QuintGao/GKNavigationBar" 最近更新 ``` +* 1.8.3 - 2023.03.24 1、push、pop转场动画修改为只截取tabBar播放 2、缩放转场动画优化 * 1.8.2 - 2022.12.27 iPhone 14适配优化 * 1.8.1 - 2022.09.29 移除导航栏上的点击事件 * 1.8.0 - 2022.09.16 导航栏高度适配iPhone 14系列新设备