SCNView to UIView?

2019-09-14 14:27发布

问题:

Is it possible to translate from a SCNView to a UIView? I have a login button from an overlay on my SCNView but I want the login button to take the user to a UIView to login.

回答1:

May not be the most elegant way to do it but something like this might work for you.....

- (void) handleTap:(UITapGestureRecognizer*)gestureRecognizer {

    // get tap location
    CGPoint p = [gestureRecognizer locationInView:scnView];

    // convert to sk scene coordinates
    CGPoint p2D = [scnView.overlaySKScene convertPointFromView:p];
    //test if we hit the login button
    SKNode *loginButton = [scnView.overlaySKScene nodeAtPoint:p2D];

    // assuming your loginButton is of type SKLabelNode
    if (loginButton != nil && ( [loginButton isMemberOfClass:[SKLabelNode class]]  )) // add other tests here
    { 
        // Here you can add code to transition to another 
        // view controller to handle logins


    } else {
        // do hit test on scnView here for the 3D scene
        // .........
    }

}