SCNAction 完成处理程序等待手势执行 [英] SCNAction completion handler awaits gesture to execute

查看:86
本文介绍了SCNAction 完成处理程序等待手势执行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个由按钮触发的 SCNNodes 动画.随后按下按钮,动画反转.正向动画总是工作正常但反向动画有时会挂断.也就是说,它将在完成处理程序之前播放部分然后冻结.但是当我应用我的三个手势(平移、平移、缩放)中的任何一个时,它会解除挂起并完成处理程序部分.相关代码:

I have an animation of SCNNodes triggered by a button. On a subsequent press of the button, the animation reverses. The forward animation always works fine But the reverse animation will sometimes hang up. That is, it will play the portion before the completion handler then freeze. But when I apply any of my three gestures (pan, translate, zoom) it un-hangs and completes the handler portion. The relevant code:

            else if buttonToggle_1 == true {  buttonToggle_1 = false
                let moveWaterBack = SCNAction.moveTo(homePosition_2, duration: 1)
                let moveValineBack = SCNAction.moveTo(awayPosition_1, duration: 1)

                atomsNode_3.hidden = false
                bondsNode_3.hidden = false

                hideTransients(true)

                atomsNode_3.runAction(moveWaterBack)
                bondsNode_3.runAction(moveWaterBack,
                    completionHandler: {
                        self.atomsNode_2.runAction(moveValineBack) ;
                        self.bondsNode_2.runAction(moveValineBack) ;
                        self.atomsNode_3.removeFromParentNode() ;
                        self.bondsNode_3.removeFromParentNode() ;
                        hideTransients(false)
                    })
            }

hideTransients()) 调用取消隐藏五个节点,按名称访问它们.有时完成挂起,有时不会.但是,如果它在保持在同一页面上的特定会话中挂起,它将继续在后续按钮切换时挂起.我还没有弄清楚任何因果关系.我已将 removeFromParentNode() 调用更改为 hidden = true,目前正在运行,但让我感到紧张.

The hideTransients()) call unhides five nodes, accessing them by name. Sometimes completion hangs, sometimes it doesn't. However if it is hanging in a particular session of remaining on the same page, it will continue to hang on subsequent button toggling. I haven't figured out any cause-effect relationship. I have changed the removeFromParentNode() calls to hidden = true and this currently is working but makes me nervous to rely on.

这里到底会发生什么?

编辑 1:虽然它一直在工作,但我已经看到几次挂断(很多)使用后面提到的代码,所以这不是严格由于 removeFromParentNode() 电话.

edit 1: Although it's been working pretty consistently, I have seen the hang-ups a couple times (out of many) using the latter code mentioned so this is not strictly due to the removeFromParentNode() calls.

推荐答案

在操作中调用 SCNNode.removeFromParentNode() 对我来说似乎很可疑.我还看到了另一种情况,这似乎导致了不稳定的行为,尽管没有文件表明您不应该这样做.

Invoking SCNNode.removeFromParentNode() within an action seems fishy to me. I have seen one other case where that seemed to be causing erratic behavior, although there's no documentation that you shouldn't do it.

我认为 SCNAction.removeFromParentNode() 的存在是一个很大的提示,调用该操作比直接操作节点树更可取.

I think the existence of SCNAction.removeFromParentNode() is a pretty big hint, and invoking that action would be preferable to directly manipulating the node tree.

使用 SCNAction.group()SCNAction.sequence() 会让你的代码更简单.

Using SCNAction.group() and SCNAction.sequence() would make your code a bit simpler.

这篇关于SCNAction 完成处理程序等待手势执行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆