【发布时间】:2015-11-03 12:27:42
【问题描述】:
我有通常的视图控制器,我想显示另一个包含 SCNView 的 ViewController
如果我使用 presentViewController 或 showViewController 它不起作用。马上就结束了。我的意思是,场景没有显示。
感谢您的回答!
对不起我的英语不好
让我们描述一下我的项目。我有包含主菜单的 ViewContrioller,我有包含骰子下落的 SCNView。 这是包含 SCNView 的 ViewController:
self.scene = [SCNScene sceneNamed:@"dice.dae"];
self.scene.physicsWorld.gravity = SCNVector3Make(0, -16, 0);
self.scene.physicsWorld.speed = 2.5;
self.cameraNode = [SCNNode node];
self.cameraNode.camera = [SCNCamera camera];
[self.scene.rootNode addChildNode:self.cameraNode];
self.cameraNode.position = SCNVector3Make(0, 20, 20);
self.cameraNode.transform = SCNMatrix4Rotate(self.cameraNode.transform,M_PI/3.0, -5, 0, 0);
self.diceNode = [self.scene.rootNode childNodeWithName:@"dice" recursively:YES];
SCNPhysicsBody* diceBody = [SCNPhysicsBody bodyWithType:SCNPhysicsBodyTypeDynamic shape:[SCNPhysicsShape shapeWithNode: self.diceNode options:nil ]];
self.diceNode.physicsBody = diceBody;
CGFloat zVelocity = arc4random()%10+5;
CGFloat xVelocity = arc4random()%5;
self.diceNode.physicsBody.velocity = SCNVector3Make(xVelocity, 0, -zVelocity);
CGFloat xAngVelocity = arc4random()%12 + 5;
CGFloat yAngVelocity = arc4random()%4 + 1;
CGFloat zAngVelocity = arc4random()% 13 + 9;
self.diceNode.physicsBody.angularVelocity = SCNVector4Make(-xAngVelocity, yAngVelocity, -zAngVelocity, 0.8);
self.diceNode.physicsBody.mass = 100.0;
self.diceNode.physicsBody.friction = 1;
SCNNode *field = [self.scene.rootNode childNodeWithName:@"field" recursively:YES];
field.physicsBody = [SCNPhysicsBody bodyWithType:SCNPhysicsBodyTypeStatic shape:[SCNPhysicsShape shapeWithNode:field options:nil]];
field.physicsBody.friction = 1;
self.scnView = (SCNView *)self.view;
self.scnView.frame = self.view.frame;
self.scnView.scene = self.scene;
self.scnView.allowsCameraControl = YES;
self.scnView.showsStatistics = YES;
self.scnView.backgroundColor = [UIColor blackColor];
self.scnView.delegate = self;
我尝试从主菜单显示这个 ViewController
DiceScene* dice = [[DiceScene alloc] init];
[self presentViewController:dice animated:YES completion:^{
NSLog(@"completion");
}];
而且我的 DiceScene 没有显示,它立即完成而没有错误。
【问题讨论】:
-
你能提供一些代码吗,你已经试过了。
-
所以
DiceScene是UIViewController的子类(不是SCNScene对吗?)。self.view是如何配置的(代码或 IBOutlet)?你确定不是nil? -
如果带有 DiceScene 的 ViewController 是初始视图控制器,它的工作,但如果我从其他 ViewController 调用它,它就不起作用
标签: ios objective-c viewcontroller scenekit