Latest 1.0.1
Homepage https://github.com/xinyuly/KINavigationController
License MIT
Platforms ios 9.0, requires ARC
Authors

NavigationDemo

三种popViewController的效果,例如淘宝、京东的“整体返回”效果

效果图:

image

实现思路:

1.创建Pan手势识别器

2.实现手势的相应事件

3.创建截图需要的backgroundView和作为遮罩的blackMask,存放截图所需的数组

4.在push前截图,并保存

5.重写常用的pop方法,在pop前删除相应的截图

override func popViewController(animated: Bool) -> UIViewController?
override func popToViewController(_ viewController: UIViewController, animated: Bool) -> [UIViewController]?
override func popToRootViewController(animated: Bool) -> [UIViewController]? 

到此处能实现手势整体返回的效果,要实现点击返回按钮也能整体返回,需要自定义返回动画。实现协议UIViewControllerAnimatedTransitioning

6.让navigationController遵守UINavigationControllerDelegate实现下面的方法,在方法里面可根据operation判断需要自定义的类型(pop/push)

 func navigationController(_ navigationController: UINavigationController, 
 animationControllerFor operation: UINavigationControllerOperation, 
 from fromVC: UIViewController,
  to toVC: UIViewController) -> UIViewControllerAnimatedTransitioning?

7.使用一个类实现UIViewControllerAnimatedTransitioning协议

func transitionDuration(using transitionContext: UIViewControllerContextTransitioning?) -> TimeInterval

//定义动画
func animateTransition(using transitionContext: UIViewControllerContextTransitioning)

Latest podspec

{
    "name": "KINavigationController",
    "version": "1.0.1",
    "summary": "u4e09u79cdpopViewControlleru7684u6548u679c,u4f8bu5982u6dd8u5b9du3001u4eacu4e1cu7684u201cu6574u4f53u8fd4u56deu201du6548u679c",
    "homepage": "https://github.com/xinyuly/KINavigationController",
    "license": "MIT",
    "authors": {
        "lixinyu": "[email protected]"
    },
    "platforms": {
        "ios": "9.0"
    },
    "source": {
        "git": "https://github.com/xinyuly/KINavigationController.git",
        "tag": "1.0.1"
    },
    "source_files": "KINavigationController/*.swift",
    "requires_arc": true,
    "pod_target_xcconfig": {
        "SWIFT_VERSION": "4.0"
    }
}

Pin It on Pinterest

Share This