Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/118.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 如果不使用interactionController之类的辅助对象,如何在自定义pop转换中插入toViewController?_Ios_Swift_Uinavigationcontroller - Fatal编程技术网

Ios 如果不使用interactionController之类的辅助对象,如何在自定义pop转换中插入toViewController?

Ios 如果不使用interactionController之类的辅助对象,如何在自定义pop转换中插入toViewController?,ios,swift,uinavigationcontroller,Ios,Swift,Uinavigationcontroller,这是一个自定义的弹出式手势,用于UINavigationController,它不使用像interactionController这样的助手。pop转换完全是手动的,效果很好,只是当手势开始时,我需要在fromViewController下面插入到ViewController。由于此脚本现在已存在,因此只有在手势成功完成后才会显示toViewController 这就是快照发挥作用的地方吗?我从来没用过。或者我应该将toViewController放入superview中,然后在手势完成后将其移

这是一个自定义的弹出式手势,用于
UINavigationController
,它不使用像
interactionController
这样的助手。pop转换完全是手动的,效果很好,只是当手势开始时,我需要在
fromViewController
下面插入
到ViewController
。由于此脚本现在已存在,因此只有在手势成功完成后才会显示
toViewController

这就是快照发挥作用的地方吗?我从来没用过。或者我应该将toViewController放入superview中,然后在手势完成后将其移除

func popPanGestureHandler(_ gesture: UIPanGestureRecognizer) {

    guard let fromViewController = currentViewController,
        let toViewController = previousViewController else {
        return
    }

    let translation: CGPoint = gesture.translation(in: gesture.view)
    let velocity: CGPoint = gesture.velocity(in: gesture.view)

    switch gesture.state {

    case .began:

        // insert toViewController here
        fromViewController.view.center = CGPoint(x: fromViewController.view.center.x + translation.x, y: fromViewController.view.center.y)
        gesture.setTranslation(CGPoint.zero, in: gesture.view)

    case .changed:

        fromViewController.view.center = CGPoint(x: fromViewController.view.center.x + translation.x, y: fromViewController.view.center.y)
        gesture.setTranslation(CGPoint.zero, in: gesture.view)

        // force finish
        if fromViewController.view.frame.origin.x > (fromViewController.view.frame.width / 3) * 2 {

            UIView.animate(withDuration: 0.2, delay: 0, options: UIViewAnimationOptions.curveEaseOut, animations: {
                fromViewController.view.frame.origin.x = fromViewController.view.frame.width
            }, completion: {
                (finished: Bool) in
                self.popViewController(animated: false)

            })

            gesture.isEnabled = false
            gesture.isEnabled = true

        }

    case .ended:

        // cancel
        if fromViewController.view.frame.origin.x < fromViewController.view.frame.width / 2 && velocity.x < 750 {

            UIView.animate(withDuration: 0.2, delay: 0, options: UIViewAnimationOptions.curveEaseOut, animations: {
                fromViewController.view.frame.origin.x = 0
            }, completion: {
                (finished: Bool) in
                self.dismiss(animated: true, completion: nil)
            })

            gesture.isEnabled = false
            gesture.isEnabled = true

        }

        // finish
        else if fromViewController.view.frame.origin.x >= fromViewController.view.frame.width / 2 {

            UIView.animate(withDuration: 0.2, delay: 0, options: UIViewAnimationOptions.curveEaseOut, animations: {
                fromViewController.view.frame.origin.x = fromViewController.view.frame.width
            }, completion: {
                (finished: Bool) in
                self.popViewController(animated: false)
            })

            gesture.isEnabled = false
            gesture.isEnabled = true

        }

        // finish
        else if velocity.x >= 750 {

            UIView.animate(withDuration: 0.2, delay: 0, options: UIViewAnimationOptions.curveEaseOut, animations: {
                fromViewController.view.frame.origin.x = fromViewController.view.frame.width
            }, completion: {
                (finished: Bool) in
                self.popViewController(animated: false)
            })

            gesture.isEnabled = false
            gesture.isEnabled = true

        }

    default:
        break

    }

}
func-popPanGestureHandler(uu手势:uipangestrerecognizer){
来自ViewController的保护let=currentViewController,
让toViewController=previousViewController-else{
返回
}
let translation:CGPoint=signature.translation(in:signature.view)
让速度:CGPoint=手势.速度(in:手势.视图)
开关状态{
案例.开始:
//在此处插入视图控制器
fromViewController.view.center=CGPoint(x:fromViewController.view.center.x+translation.x,y:fromViewController.view.center.y)
手势.setTranslation(CGPoint.zero,in:手势.view)
案例。更改:
fromViewController.view.center=CGPoint(x:fromViewController.view.center.x+translation.x,y:fromViewController.view.center.y)
手势.setTranslation(CGPoint.zero,in:手势.view)
//强制完成
如果fromViewController.view.frame.origin.x>(fromViewController.view.frame.width/3)*2{
UIView.animate(持续时间:0.2,延迟:0,选项:UIViewAnimationOptions.curveEaseOut,动画:{
fromViewController.view.frame.origin.x=fromViewController.view.frame.width
},完成日期:{
(完成:Bool)在
self.popViewController(动画:false)
})
signature.isEnabled=false
signature.isEnabled=true
}
案件结束:
//取消
如果fromViewController.view.frame.origin.x=fromViewController.view.frame.width/2,则为else{
UIView.animate(持续时间:0.2,延迟:0,选项:UIViewAnimationOptions.curveEaseOut,动画:{
fromViewController.view.frame.origin.x=fromViewController.view.frame.width
},完成日期:{
(完成:Bool)在
self.popViewController(动画:false)
})
signature.isEnabled=false
signature.isEnabled=true
}
//完成
否则,如果速度.x>=750{
UIView.animate(持续时间:0.2,延迟:0,选项:UIViewAnimationOptions.curveEaseOut,动画:{
fromViewController.view.frame.origin.x=fromViewController.view.frame.width
},完成日期:{
(完成:Bool)在
self.popViewController(动画:false)
})
signature.isEnabled=false
signature.isEnabled=true
}
违约:
打破
}
}