我有通常的视图控制器,我想显示包含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没有显示,它立即完成而没有错误。
答案 0 :(得分:0)
试试这个:
ViewController中的:
DiceScene* dice = [[DiceScene alloc] init];
[self setView:dice];