iOS 自定义Present转场动画如Push/Pop

场景

项目中碰见一个场景,VC没有UINavigationController,可是须要PushPop的动画效果。 一开始使用了MZFormSheetPresentationViewController来实现Push效果,可是却没有Pop的边缘返回手势。本着求Github不如求己的原则,手撸了一个库出来,WHPopAnimationgit

效果图.gif

Push/Pop转场效果及实现

  1. Push转场效果github

    • view.frame从右屏外平移到屏幕正中
    • VC透明度从1.0变成0.5
    • VC向左平移110
    • 时长0.3s
  2. Pop转场效果bash

    • view.frame从屏幕正中平移到右屏外
    • VC透明度从0.5变成1.0
    • VC向右平移110
    • 时长0.4s
    • VCself.view须要添加UIScreenEdgePanGestureRecognizer边缘手势,平移超过屏幕中线则dismiss(Pop),反之回弹回去。
  3. 实现:<UIViewControllerAnimatedTransitioning>协议UIPercentDrivenInteractiveTransition手势过渡管理对象动画

WHPopAnimation 接入说明

无需管理<UIViewControllerAnimatedTransitioning>协议UIPercentDrivenInteractiveTransition手势过渡管理对象。 AVcBVc弹出来(Present出来),只须要AVc继承WHPopViewControllerPresent调用代码也和以前同样(WHPopViewController中重写该方法)。spa

- (void)presentViewController:(UIViewController *)viewControllerToPresent animated:(BOOL)flag completion:(void (^)(void))completion 
复制代码

Ps.假如你同一个VC既须要Push的转场效果,也须要Present的转场效果,你能够修改上面的方法,增长一个BOOL isPushAnimation的参数。code

Github连接:

github.com/Balzac64672…orm

violet.jpg

######以为不错就点个赞吧😀😀cdn

相关文章
相关标签/搜索