场景
项目中遇见一个场景,VC没有UINavigationController,但是需要Push和Pop的动画效果。
一开始使用了MZFormSheetPresentationViewController来实现Push效果,但是却没有Pop的边缘返回手势。本着求Github不如求己的原则,手撸了一个库出来,WHPopAnimation。
Push/Pop转场效果及实现
-
Push转场效果view.frame从右屏外平移到屏幕正中- 父
VC透明度从1.0变成0.5 - 父
VC向左平移110 - 时长
0.3s
-
Pop转场效果view.frame从屏幕正中平移到右屏外- 父
VC透明度从0.5变成1.0 - 父
VC向右平移110 - 时长
0.4s - 子
VC的self.view需要添加UIScreenEdgePanGestureRecognizer边缘手势,平移超过屏幕中线则dismiss(Pop),反之回弹回去。
-
实现:
<UIViewControllerAnimatedTransitioning>协议和UIPercentDrivenInteractiveTransition手势过渡管理对象
WHPopAnimation 接入说明
无需管理<UIViewControllerAnimatedTransitioning>协议和UIPercentDrivenInteractiveTransition手势过渡管理对象。
AVc把BVc弹出来(Present出来),只需要AVc继承WHPopViewController,Present调用代码也和之前一样(WHPopViewController中重写该方法)。
- (void)presentViewController:(UIViewController *)viewControllerToPresent animated:(BOOL)flag completion:(void (^)(void))completion
Ps.假如你同一个VC既需要Push的转场效果,也需要Present的转场效果,你可以修改上面的方法,增加一个BOOL isPushAnimation的参数。
Github链接:
######觉得不错就点个赞吧😀😀