我知道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;
}
答案 0 :(得分:0)
如果你想让viewcontroller拥有一个可以使用nextResponder
方法
首先,您从gestureRecognizer获取视图:
UIView *view = [gestureRecognizer view];
然后搜索包含视图的viewcontroller
<强> 编辑: 强>
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];
}
}
... 我重写了方法获取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;
}
new edit ::
您的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;