gsyhei / GXTransition

iOS常用转场动画(包括自定义和OC自带转场动画)
MIT License
29 stars 10 forks source link

关于gx_presentViewController之后,手势返回的问题。 #3

Open kakashilw opened 4 years ago

kakashilw commented 4 years ago

您好,首先很感谢提供了这么方便的库,我们在使用的时候遇到一个问题,就是当用gx_presentViewController一个nav之后,

[self gx_presentViewController:navc style:GXAnimationStyleCubeRight interacting:YES completion:nil];

然后这个nav里面再push子页面,手势返回会直接返回第一个页面,而不是上一级页面。

我看您在另一个问题回到了这句【navigationController的delegate是同一个当然动画也是一样了,需要自己设置!】

我试了几种方法还是不能达到效果,不知道可否详细说说nav里要具体怎么设置,就可以既支持nav的手势返回,也支持gx_presentViewController的手势返回。

gsyhei commented 4 years ago

是我没注意到这个问题,我在1.0.3版本已经修复了这个问题。

kakashilw commented 4 years ago

十分感谢,经测试1.0.3这个问题已经OK了!

不过我这边遇到了另一个小问题想请教,就是我们用到了custom present 的GXAnimationStyleCube这个效果,不过我们是想让它从左往右旋转,然后我修改了GXAnimationCubeDelegate.m这个文件,改成这样:

// // GXTransitionCubeDelegate.m // GXTransitionSample // // Created by Gin on 2020/4/15. // Copyright © 2020 gin. All rights reserved. //

import "GXAnimationCubeDelegate.h"

@interface GXAnimationCubeDelegate () @end

@implementation GXAnimationCubeDelegate

pragma mark - Overwrite

// CATransform3D transform = CATransform3DIdentity; // transform = CATransform3DTranslate(transform, 0, 0, width * 0.5); // transform = CATransform3DRotate(transform, 0, 0, 0, 0); // fromSnapshotView.layer.transform = transform;

CATransform3D transform = CATransform3DIdentity;
transform = CATransform3DTranslate(transform, width * 0.5, 0, 0);
transform = CATransform3DRotate(transform, M_PI_2, 0, 1.0, 0);
fromSnapshotView.layer.transform = transform;

[transitionContext.containerView addSubview:fromSnapshotView];

// transform = CATransform3DIdentity; // transform = CATransform3DTranslate(transform, width * 0.5, 0, 0); // transform = CATransform3DRotate(transform, M_PI_2, 0, 1.0, 0);

transform = CATransform3DIdentity;
transform = CATransform3DTranslate(transform, 0, 0, width * 0.5);
transform = CATransform3DRotate(transform, 0, 0, 0, 0);

toVC.view.layer.transform = transform;
[transitionContext.containerView addSubview:toVC.view];

// CATransform3D transform3D = CATransform3DIdentity; // transform3D.m34 = 1.0 / -1200; // transform3D = CATransform3DTranslate(transform3D, 0, 0, -width * 0.5); // transitionContext.containerView.layer.sublayerTransform = transform3D; // transform3D = CATransform3DRotate(transform3D, -M_PI_2, 0, 1.0, 0);

CATransform3D transform3D = CATransform3DIdentity;
transform3D.m34 = 1.0 / -1200;
transform3D = CATransform3DTranslate(transform3D, 0, 0, -width * 0.5);
transform3D = CATransform3DRotate(transform3D, -M_PI_2, 0, 1.0, 0);
transitionContext.containerView.layer.sublayerTransform = transform3D;
transform3D = CATransform3DIdentity;
transform3D.m34 = 1.0 / -1200;
transform3D = CATransform3DTranslate(transform3D, 0, 0, -width * 0.5);

[self addBackgroundViewToView:fromSnapshotView];
[self addShadowToView:toVC.view];
[self animateWithContext:transitionContext isPresent:YES animations:^{
    transitionContext.containerView.layer.sublayerTransform = transform3D;
} completion:^(BOOL finished) {
    fromVC.view.hidden = NO;
    [fromSnapshotView removeFromSuperview];
    transitionContext.containerView.layer.sublayerTransform = CATransform3DIdentity;
    toVC.view.layer.transform = CATransform3DIdentity;
}];

}

// CATransform3D transform = CATransform3DIdentity; // transform = CATransform3DTranslate(transform, width * 0.5, 0, 0); // transform = CATransform3DRotate(transform, M_PI_2, 0, 1.0, 0);

CATransform3D transform = CATransform3DIdentity;
transform = CATransform3DTranslate(transform, 0, 0, width * 0.5);
transform = CATransform3DRotate(transform, 0, 0, 0, 0);

fromSnapshotView.layer.transform = transform;

UIView *toSnapshotView = [toVC.view snapshotViewAfterScreenUpdates:NO];
[transitionContext.containerView addSubview:toSnapshotView];
toVC.view.hidden = YES;

// transform = CATransform3DIdentity; // transform = CATransform3DTranslate(transform, 0, 0, width * 0.5); // transform = CATransform3DRotate(transform, 0, 0, 0, 0);

transform = CATransform3DIdentity;
transform = CATransform3DTranslate(transform, width * 0.5, 0, 0);
transform = CATransform3DRotate(transform, M_PI_2, 0, 1.0, 0);

toSnapshotView.layer.transform = transform;

// CATransform3D transform3D = CATransform3DIdentity; // transform3D.m34 = 1.0 / -1200; // transform3D = CATransform3DTranslate(transform3D, 0, 0, -width 0.5); // transform3D = CATransform3DRotate(transform3D, -M_PI_2, 0, 1.0, 0); // transitionContext.containerView.layer.sublayerTransform = transform3D; // transform3D = CATransform3DIdentity; // transform3D.m34 = 1.0 / -1200; // transform3D = CATransform3DTranslate(transform3D, 0, 0, -width 0.5);

CATransform3D transform3D = CATransform3DIdentity;
transform3D.m34 = 1.0 / -1200;
transform3D = CATransform3DTranslate(transform3D, 0, 0, -width * 0.5);
transitionContext.containerView.layer.sublayerTransform = transform3D;
transform3D = CATransform3DRotate(transform3D, -M_PI_2, 0, 1.0, 0);

[self addBackgroundViewToView:toSnapshotView];
[self addShadowToView:fromSnapshotView];
[self animateWithContext:transitionContext isPresent:NO animations:^{
    transitionContext.containerView.layer.sublayerTransform = transform3D;
} completion:^(BOOL finished) {
    toVC.view.hidden = NO;
    fromVC.view.hidden = NO;
    [toSnapshotView removeFromSuperview];
    [fromSnapshotView removeFromSuperview];
    transitionContext.containerView.layer.sublayerTransform = CATransform3DIdentity;
}];

}

@end

把presentViewAnimation和dismissViewAnimation中涉及到旋转的对调了,然后点击present到下一个页面,以及点击返回按钮,旋转会上一个页面,动画效果都OK。

但是当手势侧滑的时候,就失效了,没有动画效果,直接就返回了。

所以想请教如果想支持侧滑的话,还需要改动里面的哪部分代码?

gsyhei commented 4 years ago

我说一下,我这边暂时没时间,这里我看了一下,主要是全屏手势和你这样逆转我这块代码相当于手势反过来了,就是说我本来想左滑返回,但是你实际手势在VC上是反向的手势,这样对不上。你如果愿意等的话我周末再帮你弄下

kakashilw commented 4 years ago

嗯,感谢,等你有时间给弄弄就行。

点击进入的两边都可以转入效果确实是有需求的,比如一个主页面,左右两边都有按钮,点右边按钮,往左转入;点左边按钮,往右转入,这样会给用户两边都有页面的动画感,用户体验很棒!

然后这个从左边往右转入,再返回的效果,这两天我试了几种都是直接返回了,没有找到更好的方法,所以,期待你这边好的方案。:)

gsyhei commented 4 years ago

1.0.4已经解决并加入了cube左右方向,记得点赞!

kakashilw commented 4 years ago

嗯 已经试了 这个版本已完美支持cube左右方向了 这么好的库和作者 必须点赞!

kakashilw commented 4 years ago

然后现在有个新的问题,是点击demo里gx_pushViewController相关的都会闪退。

好像是- (void)configureTransition:(UIViewController*)presentingViewController isPush:(BOOL)isPush interacting:(BOOL)interacting这里面的和push的有冲突造成的。