本文介绍了sceneDidLoad 被调用了两次?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 Xcode 8、swift 3,我使用游戏模板创建了一个 iOS 应用程序,并启用了实体.我注意到我看到一些初始精灵的双节点计数,即使我只使用了一次 addChild.

Using Xcode 8, swift 3 and I create a iOS application using the game template with entities enabled. I notice I was seeing double node count for some initial sprites even though I only used addChild once.

我加了

override func sceneDidLoad() {
print(#function) ... }

到代码,不知道为什么会被调用两次.

to the code and no idea why this is being called twice.

日志文件...

2016-09-20 10:21:31.482 MMDecon1[3295:791435] SKUtil.m: MGGetBoolAnswer is not available in the simulator.
sceneDidLoad()
sceneDidLoad()

我加了

override func didMove(to view: SKView) {..}

并将我的初始化代码放在这里作为临时修复.

and put my initialisation code in here as a temporary fix.

有人知道为什么使用实体的默认游戏应用代码会触发两次 sceneDidLoad() 吗?

Does any one know why sceneDidLoad() is being fired twice with the default game app code using entities?

推荐答案

一般情况下,sceneDidLoad 只会被调用一次.但是,如果发送了内存警告,则 UIViewController 会释放其场景,如果视图控制器不可见,则将其设置为 nil.下次出现场景时,视图控制器将重新加载场景并再次调用 sceneDidLoad.

Normally, sceneDidLoad is only called one time. However, if a memory warning is sent then UIViewController releases its scene and sets it to nil if the view controller isn't visible. The next time that the scene appears the view controller will reload the scene and call sceneDidLoad again.

您必须假设可以多次调用 sceneDidLoad.

You have to assume that sceneDidLoad can be called multiple times.

实施 didReceiveMemoryWarning 并记录或设置断点以查看发生了什么.

Implement didReceiveMemoryWarning and log or set a breakpoint to see what is happening.

这篇关于sceneDidLoad 被调用了两次?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-20 11:38