Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c 未从类的正确实例调用MouseDown事件_Objective C - Fatal编程技术网

Objective c 未从类的正确实例调用MouseDown事件

Objective c 未从类的正确实例调用MouseDown事件,objective-c,Objective C,我有一个名为PointsView的自定义类,它是SCNView的一个子类 @interface PointsView : SCNView <SCNSceneRendererDelegate> 这将使用SCNView和SCNScene初始化pointsView,两者都是在ViewController中创建的,并链接到我的故事板。SCNView和SCNScene的属性在PointsView类中设置 @implementation PointsView - (id)initView:(

我有一个名为PointsView的自定义类,它是SCNView的一个子类

@interface PointsView : SCNView <SCNSceneRendererDelegate>
这将使用SCNView和SCNScene初始化pointsView,两者都是在ViewController中创建的,并链接到我的故事板。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中初始化的那个。我做错什么了吗?还是我错过了什么?非常感谢您的帮助

如果有人需要更多信息,请询问


谢谢。

我设法解决了这个问题。我使用了NSEvent中的firstResponder属性,该属性已设置为ViewController。从那里我可以访问我已经初始化的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;
}