Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios ';弹出窗口';查看动画_Ios_Swift - Fatal编程技术网

Ios ';弹出窗口';查看动画

Ios ';弹出窗口';查看动画,ios,swift,Ios,Swift,我正在尝试解决如何复制此处显示的“弹出”视图动画:。我正在使用此当前代码来显示我的viewController,但目前只有一个淡入淡出动画工作。如何创建所显示的动画?这是习俗吗 let popup : SearchViewController = self.storyboard?.instantiateViewController(withIdentifier: "SearchViewController") as! SearchViewController self.present

我正在尝试解决如何复制此处显示的“弹出”视图动画:。我正在使用此当前代码来显示我的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)
        }
    }

是的,这似乎是一个自定义的转换。您可以通过
UIViewControllerTransitioningDelegate
UIViewControllerAnimatedTransitioning

以下是一个很好的教程:

正确理解代理和动画控制器后,可以通过提供的
containerView
编写自己的当前/取消动画

一种方法是通过
UIPresentationController
类上的
FrameOfPresentedViewWinContainerView
变量简单地指定所需的帧,并通过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
中)制作一个简单的动画,以显示“淡入”效果。还要注意的是,有很多方法可以做到这一点,这只是其中之一