Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

fypj2013

macrumors newbie
Original poster
Mar 12, 2013
6
0
Hi all

I am creating an application which uses gyroscope on a 3D model. Currently I am able to display my 3D model and using the gyroscope. But I want to enable user when on click certain function of the model, it will link to a new UIViewController. My 3D model and gyroscope is in a UIView mode called EAGL View. Is it possible for me to link the EAGL View to UIViewController?

Here are the codes that i had done, in EAGL View but it doesn't work.

Code:
- (void)scrollViewDoubleTapped:(UITapGestureRecognizer*)recognizer {
    
    
   CGPoint pointInView = [recognizer locationInView:self];
    NSLog(@"%f , %f",pointInView.x,pointInView.y);
    
    // get the coordinates
    if ((pointInView.x >= (231.0) && pointInView.x <=(293) && pointInView.y >= (162)  && pointInView.y <=(218)) )
    {
        
         // is this how we push to next viewcontroller here?
          UIView *a = [recognizer view];
          UIViewController *viewController = [self getViewControllerFromView:a];

            
        TestViewViewController *newViewController = [[ TestViewViewController alloc]initWithNibName:nil bundle:nil];
        [viewController.navigationController pushViewController:newViewController animated:YES];
    
        
           
        
        [self viewController];
        }
     
    
    
}





-(UIViewController*)getViewControllerFromView:(UIView*) a
{
    if([[a nextResponder] isKindOfClass:[UIViewController class]])
    {
        return (UIViewController*)[a nextResponder];
    }
    else {
        
        for (UIView *next = [a superview]; next; next = next.superview)
        {
            UIResponder *nextResponder = [next nextResponder];
            
            if([nextResponder isKindOfClass:[UIViewController class]])
            {
                return (UIViewController*)nextResponder;
            }
        }
    }
    
    return nil;
}
 
Last edited by a moderator:
Hi all

I am creating an application which uses gyroscope on a 3D model. Currently I am able to display my 3D model and using the gyroscope. But I want to enable user when on click certain function of the model, it will link to a new UIViewController. My 3D model and gyroscope is in a UIView mode called EAGL View. Is it possible for me to link the EAGL View to UIViewController?

Here are the codes that i had done, in EAGL View but it doesn't work.

Code:
- (void)scrollViewDoubleTapped:(UITapGestureRecognizer*)recognizer {
    
    
   CGPoint pointInView = [recognizer locationInView:self];
    NSLog(@"%f , %f",pointInView.x,pointInView.y);
    
    // get the coordinates
    if ((pointInView.x >= (231.0) && pointInView.x <=(293) && pointInView.y >= (162)  && pointInView.y <=(218)) )
    {
        
         // is this how we push to next viewcontroller here?
          UIView *a = [recognizer view];
          UIViewController *viewController = [self getViewControllerFromView:a];

            
        TestViewViewController *newViewController = [[ TestViewViewController alloc]initWithNibName:nil bundle:nil];
        [viewController.navigationController pushViewController:newViewController animated:YES];
    
        
           
        
        [self viewController];
        }
     
    
    
}





-(UIViewController*)getViewControllerFromView:(UIView*) a
{
    if([[a nextResponder] isKindOfClass:[UIViewController class]])
    {
        return (UIViewController*)[a nextResponder];
    }
    else {
        
        for (UIView *next = [a superview]; next; next = next.superview)
        {
            UIResponder *nextResponder = [next nextResponder];
            
            if([nextResponder isKindOfClass:[UIViewController class]])
            {
                return (UIViewController*)nextResponder;
            }
        }
    }
    
    return nil;
}


An EAGALView can be part of any view hierarchy. it acts like any other view.

I have a custom view that's backed by an OpenGL layer in an application I'm working on, and it handles tap gestures just like any other view.

You should make your OpenGL view part of a view controller, and then handle the tap gesture in your view controller like you would any other view.

As the other poster suggested, enclosing your view controller that contains an OpenGL view inside a navigation controller would be a good way to go. Then you could push a new view controller when the user taps on your OpenGL view.
 
Please Help

Hi, so all I have to do is to create a new UIViewController and link it to my EAGLview which contains the OpenGL?
 
Hi, so all I have to do is to create a new UIViewController and link it to my EAGLview which contains the OpenGL?

Sure. Set userInteractionEnabled on your GL view, and attach a gesture recognizer. Have the gesture recognizer invoke a method in the view controller that hosts the GL view. In that method, create and push a new view controller.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.