Skip to content

Commit

Permalink
转场动画优化
Browse files Browse the repository at this point in the history
  • Loading branch information
QuintGao committed Mar 24, 2023
1 parent 4bf88a5 commit 7043589
Show file tree
Hide file tree
Showing 9 changed files with 102 additions and 83 deletions.
2 changes: 1 addition & 1 deletion GKNavigationBar.podspec
Original file line number Diff line number Diff line change
@@ -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'
Expand Down
6 changes: 1 addition & 5 deletions GKNavigationBar/GestureHandle/GKGestureHandleConfigure.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
4 changes: 1 addition & 3 deletions GKNavigationBar/GestureHandle/GKGestureHandleConfigure.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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();
Expand Down
77 changes: 43 additions & 34 deletions GKNavigationBar/GestureHandle/GKPopAnimatedTransition.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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];
}];
}

Expand Down
76 changes: 46 additions & 30 deletions GKNavigationBar/GestureHandle/GKPushAnimatedTransition.m
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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];
}];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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";
Expand All @@ -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;
Expand All @@ -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";
};
Expand Down
2 changes: 0 additions & 2 deletions GKNavigationBarExample/GKNavigationBarExample/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ github "QuintGao/GKNavigationBar"
<summary><font size=4>最近更新</font></summary>

```
* 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系列新设备
Expand Down

0 comments on commit 7043589

Please sign in to comment.