我有一個名爲PointsView的自定義類,它是SCNView的子類。MouseDown事件不是從類的正確實例調用的
@interface PointsView : SCNView <SCNSceneRendererDelegate>
我在我的ViewController類中的方法viewDidLoad中初始化了一個PointsView的對象。
@implementation ViewController
- (void)viewDidLoad {
pointsView = [[PointsView alloc] initView:sceneView withScene:pointsScene];
}
這初始化pointsView有SCNView和SCNScene,無論是在視圖控制器被創建並鏈接到我的故事板。 SCNView和SCNScene的屬性在PointsView類中設置。
@implementation PointsView
- (id)initView:(SCNView *)ptsView withScene:(SCNScene *)curScene {
self = [super init];
mySCNView = ptsView;
currentScene = curScene;
mySCNView.delegate = self;
mySCNView.scene = currentScene;
mySCNView.allowsCameraControl = NO;
mySCNView.jitteringEnabled = YES;
mySCNView.showsStatistics = NO;
mySCNView.backgroundColor = [NSColor blackColor];
cameraNode = [SCNNode node];
cameraNode.camera = [SCNCamera camera];
cameraNode.position = SCNVector3Make(0, 0.4, 6);
cameraNode.transform = CATransform3DRotate(cameraNode.transform, -M_PI/7.0, 0, 0, 0);
cameraNode.orientation = SCNVector4Make(1, 0, 0, 0);
cameraNode.camera.yFov = 40.0;
cameraNode.camera.xFov = 0;
cameraNode.camera.zNear = 0.5;
[currentScene.rootNode addChildNode:cameraNode];
SCNLight *spotLight = [SCNLight light];
spotLight.type = SCNLightTypeSpot;
spotLight.color = [NSColor blackColor];
SCNNode *spotLightNode = [SCNNode node];
spotLightNode.light = spotLight;
spotLightNode.position = SCNVector3Make(-2, 1, 0);
[cameraNode addChildNode:spotLightNode];
return self;
}
我在所述PointsView類rightMouseDown事件,問題是當該方法被調用它從PointsView的實例,它是從在ViewController中初始化的一個不同的,例如所謂的;初始化後內存中的位置是0x100b032a0,並且調用rightMouseDown時,內存中的位置是0x100908630。這告訴我它不是同一個實例。
- (void)rightMouseDown:(NSEvent *)theEvent {
SCNHitTestResult *result = [self hitTestResultForEvent:theEvent];
}
我不知道爲什麼另一個實例正在用於rightMouseDown事件。我需要使用在ViewController中初始化的那個。我做錯了什麼?還是有我錯過的東西?幫助將不勝感激。
如果有人需要了解更多信息,請詢問。
謝謝。