3

我知道 uiview 没有导航控制。因此,我无法从 uiview 推送到下一个 uiviewcontroller。

这是我的方法的代码。请帮忙。谢谢!

 - (void)scrollViewDoubleTapped:(UITapGestureRecognizer*)recognizer {
    CGPoint pointInView = [recognizer locationInView:self];
    NSLog(@"%f , %f",pointInView.x,pointInView.y);

    if ((pointInView.x >= (231.0) && pointInView.x <=(293) && pointInView.y >= (193)  && pointInView.y <=(218)) )
    {

        // how to push to next viewcontroller here?

        UIView *view = [UIGestureRecognizer view]; //what should i do for this code?


        [self viewController];
    }
}

-(TestViewViewController*)viewController
{
    for (UIView *next = [self superview]; next; next = next.superview)
    {
        UIResponder *nextResponder = [next nextResponder];

        if([nextResponder isKindOfClass:[TestViewViewController class]])
        {

            return (TestViewViewController*)nextResponder;
        }
    }

    return nil;
}
4

1 回答 1

0

如果你想让 viewcontroller 有一个视图,那么你可以使用nextResponder方法

所以首先你从gestureRecognizer获得视图:

UIView *view = [gestureRecognizer view];

而不是搜索包含视图的视图控制器

看这里

编辑:

 if ((pointInView.x >= (231.0) && pointInView.x <=(293) && pointInView.y >= (193)  && pointInView.y <=(218)) )
    {

        // how to push to next viewcontroller here?

        UIView *view = [recognizer view]; //what should i do for this code?

       UIViewController *viewController = [self getViewControllerFromView:view];

       if(viewController) {
          // do whatever you want...
         UIViewController *newViewController = ...
         [viewController.navigationController pushViewController:newViewController animated:YES];
       }

    }

...我将方法 get ViewController 重写为您的案例。从某种角度来看:

-(UIViewController*)getViewControllerFromView:(UIView*) view
{
    if([[view nextResponder] isKindOfClass:[UIViewController class]])
    {
        return (UIViewController*)[view nextResponder];
    }
    else {

        for (UIView *next = [view superview]; next; next = next.superview)
        {
            UIResponder *nextResponder = [next nextResponder];

            if([nextResponder isKindOfClass:[UIViewController class]])
            {
                return (UIViewController*)nextResponder;
            }
        }
    }

    return nil;
}

新编辑::

EAGLView@property (nonatomic, retain) UIViewController *viewController; 添加@synthesize viewController = _viewController;到 .m 文件。

CoreMotionAppDelegate::

MainViewController * itemsViewController = [[MainViewController alloc]init];

    UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:itemsViewController];
    glView.viewController = itemsViewController;  


    [glView startAnimation];
    [[self window]setRootViewController:navController];

而不是在你的scrollViewDoubleTapped方法中

EAGLView *v = (EAGLView*)[recognizer view];  
UIViewController *viewController =  v.viewController;
于 2013-03-21T07:41:06.793 回答