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

相關文章
相關標籤/搜索