繁体   English   中英

“弹出”查看动画

[英]'Pop-up' View animation

我正在尝试找出如何复制此处显示的“弹出”视图动画: https : //imgur.com/a/irFqdiP 我正在使用此当前代码来显示我的viewController,但目前仅使用淡入淡出动画。 如何创建显示的动画? 这是风俗吗?

   let popup : SearchViewController = self.storyboard?.instantiateViewController(withIdentifier: "SearchViewController") as! SearchViewController
   self.presentOnRoot(with: popup)


   extension UIViewController {
        func presentOnRoot(`with` viewController : UIViewController){
            let navigationController = UINavigationController(rootViewController: viewController)
            navigationController.modalPresentationStyle = UIModalPresentationStyle.overCurrentContext
            self.present(navigationController, animated: true, completion: nil)
        }
    }

是的,这似乎是自定义转换。 您可以通过UIViewControllerTransitioningDelegateUIViewControllerAnimatedTransitioning来实现

这是一个很好的入门教程: Raywenderlich:自定义VC演示教程

一旦正确理解了委托和动画控制器,就可以通过提供的containerView编写自己的当前/关闭动画。

一种方法是通过UIPresentationController类上的frameOfPresentedViewInContainerView变量简单地指定所需的帧,并通过containerView对其显示和动画进行动画处理。 这是我正在谈论的presentationController的示例:-

class YourPresentationController: UIPresentationController {

//Do whatever stuff you want to. I've added a view with black tint to emphasise presentation 

let dimmingView: UIView = {
    let view = UIView()
    view.backgroundColor = UIColor(white: 0.0, alpha: 0.5)
    return view
}()

override func presentationTransitionWillBegin() {
    dimmingView.frame = containerView!.bounds
    dimmingView.alpha = 0.0
    containerView!.insertSubview(dimmingView, at: 0)

    presentedViewController.transitionCoordinator?.animate(alongsideTransition: { _ in
        self.dimmingView.alpha = 1.0
    })
}

override func dismissalTransitionWillBegin() {
    presentedViewController.transitionCoordinator?.animate(alongsideTransition: { _ in
        self.dimmingView.alpha = 0.0
    }) { _ in
        self.dimmingView.removeFromSuperview()
    }
}

//This variable is what I'm talking about. Just specify the frame that you would want your presented VC's view to be at:-

override var frameOfPresentedViewInContainerView: CGRect {
    var size = containerView!.bounds.size
    return CGRect(origin: CGPoint(x: 0, y: 0), size: size) 
}

override func containerViewWillLayoutSubviews() {
    dimmingView.frame = containerView!.bounds
    presentedView?.frame = frameOfPresentedViewInContainerView
}
}

...并在呈现和消除视图时(在您的UIViewControllerAnimatedTransitioning继承类的containerView中)做一个简单的动画,以显示该“淡入淡出”效果。 还要注意,有“ n”种方式可以做到这一点,而这只是其中的一种

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM