最近在做的一個(gè)小項(xiàng)目需要用到這種斷頭臺(tái)效果仅胞,后面在github上找到了對(duì)應(yīng)的代碼邓厕。
https://github.com/Yalantis/GuillotineMenu
遺憾的是在菜單頁(yè)面present一個(gè)ViewController的話,在這個(gè)ViewController dismiss后琢蛤,菜單按鈕會(huì)移到后面禁漓。
后面采用了一種取巧的方法,分別在下面的兩處代碼進(jìn)行修改:
private func animateDismissal(context: UIViewControllerContextTransitioning) {
menu = context.viewControllerForKey(UITransitionContextFromViewControllerKey)!
if menu.navigationController != nil {
let toVC = context.viewControllerForKey(UITransitionContextToViewControllerKey)!
context.containerView()!.addSubview(toVC.view)
context.containerView()!.sendSubviewToBack(toVC.view)
}
if UIDevice.currentDevice().orientation == .LandscapeLeft || UIDevice.currentDevice().orientation == .LandscapeRight {
updateChromeView()
menu.view.addSubview(chromeView!)
}
let toVC = context.viewControllerForKey(UITransitionContextToViewControllerKey)
toVC?.beginAppearanceTransition(true, animated: true)
animationDelegate?.animatorWillStartDismissal?(self)
//dimiss的時(shí)候轉(zhuǎn)移到context.containerView()
if containerMenuButton != nil {
containerMenuButton!.removeFromSuperview();
context.containerView()!.addSubview(containerMenuButton!)
}
animateMenu(menu.view, context: context)
}
//MARK: - UIDynamicAnimatorDelegate protocol implementation
extension GuillotineTransitionAnimation: UIDynamicAnimatorDelegate {
func dynamicAnimatorDidPause(animator: UIDynamicAnimator) {
if self.mode == .Presentation {
self.animator.removeAllBehaviors()
menu.view.transform = CGAffineTransformIdentity
menu.view.frame = animationContext.containerView()!.bounds
anchorPoint = CGPointZero
}
chromeView?.removeFromSuperview()
animationContext.completeTransition(true)
if self.mode == .Presentation {
let fromVC = animationContext.viewControllerForKey(UITransitionContextFromViewControllerKey)
fromVC?.endAppearanceTransition()
animationDelegate?.animatorDidFinishPresentation?(self)
//present 結(jié)束的時(shí)候罢低,把view轉(zhuǎn)移到menu上
if containerMenuButton != nil {
containerMenuButton!.removeFromSuperview();
menu.view.addSubview(containerMenuButton!);
}
} else {
let toVC = animationContext.viewControllerForKey(UITransitionContextToViewControllerKey)
toVC?.endAppearanceTransition()
animationDelegate?.animatorDidFinishDismissal?(self)
}
//Stop displayLink
displayLink.paused = true
}
}
這樣也可以在菜單頁(yè)面present出 一個(gè)新的ViewController了。