gpt4 book ai didi

objective-c - 如何从 UIView 导航到 UIViewController

转载 作者:行者123 更新时间:2023-12-04 19:36:15 25 4
gpt4 key购买 nike

我知道 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;
}

最佳答案

如果你想让 viewcontroller 有一个 View ,你可以使用 nextResponder 方法

所以首先你从 gestureRecognizer 获得 View :

UIView *view = [gestureRecognizer view];

然后搜索包含 View 的 View Controller

Look here

编辑:

 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;

关于objective-c - 如何从 UIView 导航到 UIViewController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15541851/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com