gpt4 book ai didi

swift - UIViewController 未加载属性检查器中指定的 DAE 文件

转载 作者:行者123 更新时间:2023-11-28 07:10:05 25 4
gpt4 key购买 nike

我在 Xcode 6.1.1 上使用 iOS 游戏模板创建了一个新项目,选项是:

Language: Swift

Game Technology: SceneKit

Device: Universal

应用程序“按原样”运行正常,但现在我想直接从 Xcode 上的 Interface Builder 指定 .dae 文件,所以我像这样更改了 View Controller 中的方法:

override func viewDidLoad() {
super.viewDidLoad()

let scnView = self.view as SCNView

// customize the loaded scene
if let scene = scnView.scene {

//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
// the code here is never executed because scnView.scene is nil
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

// create and add a camera to the scene
let cameraNode = SCNNode()
cameraNode.camera = SCNCamera()
scene.rootNode.addChildNode(cameraNode)

// place the camera
cameraNode.position = SCNVector3(x: 0, y: 0, z: 15)

// create and add a light to the scene
let lightNode = SCNNode()
lightNode.light = SCNLight()
lightNode.light!.type = SCNLightTypeOmni
lightNode.position = SCNVector3(x: 0, y: 10, z: 10)
scene.rootNode.addChildNode(lightNode)

// create and add an ambient light to the scene
let ambientLightNode = SCNNode()
ambientLightNode.light = SCNLight()
ambientLightNode.light!.type = SCNLightTypeAmbient
ambientLightNode.light!.color = UIColor.darkGrayColor()
scene.rootNode.addChildNode(ambientLightNode)

// retrieve the ship node
let ship = scene.rootNode.childNodeWithName("ship", recursively: true)!

// animate the 3d object
ship.runAction(SCNAction.repeatActionForever(SCNAction.rotateByX(0, y: 2, z: 0, duration: 1)))
}
}

...然后像这样在storyboard上挑出ship.dae文件

enter image description here

为什么没有加载 .dae 文件?例如,当使用 ImageView 而不是 SceneKit View 时,并从应用程序包中的资源中选择一些 .png 文件

This是项目的zip文件,如果有人想试一试。

最佳答案

我做了一些广泛的测试,我相信这是一个错误。

IB 属性都有效,除了场景之一。如果删除 GameViewController.swift 中的所有代码,您将看到背景为红色,正如您在 IB 中定义的那样。

我创建了一堆新项目,包括 Swift 和 Objective-C、iOS 和 OSX、游戏模板和常规应用程序、 Storyboard和经典 IB。他们都有同样的问题。

我查看了 IB 文件,没有发现任何异常。该属性名为 sceneName,因此我必须检查问题是否出自 Scenekit。

我决定深入挖掘一下,看看问题出在哪里。我发现 SCNView 有一个私有(private)属性,NSString *__ibSceneName;。对此进行测试证明它已正确设置。还有一个名为 - (void)set_ibSceneName:(id)arg1; 的私有(private)方法。对其进行子类化证明它被正确调用(尽管它可能只是一个经典的 setter)。

为了确保最后一次,我使用仪器记录了所有文件系统交互。以下是普通模板的结果:

Normal

这是来自 IB 的结果:

IB

我的猜测是这个函数的实现可能只是丢失了,或者没有正确创建 SCNScene。我会就此向 Apple 提交错误报告。

与此同时,您可以简单地将 SCNView 子类化,并添加自定义字符串属性,例如 myScene。然后您可以在 IB 中设置它:

Custom Property

然后,只需从属性中导入场景并将其设置为自定义子类中的初始化。如果您需要代码示例,请告诉我!

编辑 7 月 1 日:这是我从 Apple 收到的消息:

We believe this issue has been addressed in the latest Xcode 7 beta. This release includes the Xcode IDE, Swift 2 compiler, Instruments, Simulator, and latest SDKs for OS X, iOS, and watchOS.

Please test with this release. If you still have issues, please provide any relevant logs or information that could help us investigate.

Xcode 7 beta https://developer.apple.com/xcode/downloads/

关于swift - UIViewController 未加载属性检查器中指定的 DAE 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28709032/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com