How to navigate from UIView to UIViewController

Discussion in 'iOS Programming' started by fypj2013, Mar 21, 2013.

  1. fypj2013, Mar 21, 2013
    Last edited by a moderator: Mar 22, 2013

    fypj2013 macrumors newbie

    Joined:
    Mar 12, 2013
    #1
    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;
    }
    
     
  2. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #2
    Is your view actually hosted in a navigation controller?
     
  3. Duncan C macrumors 6502a

    Duncan C

    Joined:
    Jan 21, 2008
    Location:
    Northern Virginia
    #3

    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.
     
  4. fypj2013 thread starter macrumors newbie

    Joined:
    Mar 12, 2013
    #4
    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?
     
  5. Duncan C macrumors 6502a

    Duncan C

    Joined:
    Jan 21, 2008
    Location:
    Northern Virginia
    #5
    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.
     
  6. fypj2013 thread starter macrumors newbie

    Joined:
    Mar 12, 2013
    #6
    Please Help

    Hi Duncan

    It seems that i cannot find the gestureRecongnizer. Here is the link to my project http://www.mediafire.com/?14cefzmi7f671vr Please take a look at what error do i have. Thanks for your help
     
  7. Duncan C macrumors 6502a

    Duncan C

    Joined:
    Jan 21, 2008
    Location:
    Northern Virginia
    #7
    Your search term is UITapGestureRecognizer. I don't have time to download and debug your project for you.
     

Share This Page