Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios SpriteKit在场景顶部添加UIView触摸不起作用_Ios_Objective C_Uiview - Fatal编程技术网

Ios SpriteKit在场景顶部添加UIView触摸不起作用

Ios SpriteKit在场景顶部添加UIView触摸不起作用,ios,objective-c,uiview,Ios,Objective C,Uiview,当我在SpriteKit场景顶部添加自定义UIView时,我还没有弄清楚为什么我的按钮或任何可触摸元素不能工作,只是触摸不能工作。我还尝试在场景的视图和场景本身上设置userInteractionEnabled,但没有成功。这是我的代码摘录: ShopView *shopView = [[ShopView alloc] initWithFrame:CGRectMake(self.view.frame.size.width * 0.02, self.view.frame.size.height

当我在SpriteKit场景顶部添加自定义UIView时,我还没有弄清楚为什么我的按钮或任何可触摸元素不能工作,只是触摸不能工作。我还尝试在场景的视图和场景本身上设置userInteractionEnabled,但没有成功。这是我的代码摘录:

 ShopView *shopView = [[ShopView alloc] initWithFrame:CGRectMake(self.view.frame.size.width * 0.02, self.view.frame.size.height * 0.2, self.view.frame.size.width * 0.96, self.view.frame.size.height * 0.6)];

        shopView.userInteractionEnabled = YES;
        [self.gameScene.view addSubview:shopView];

根据您提供的,我只能假设您放置在顶部的视图捕捉了所有触摸,就像将手放在水龙头下一样-水不会到达下面的水槽,实际上没有任何东西到达下面的场景。考虑不同的方法。我认为您还没有完全理解如何将视图和场景结合使用。

我找到了比仅使用视图更适合我的解决方案。我可以使用它的故事板,它保持我的代码更干净。我刚刚创建了具有透明背景的模态视图控制器。我为IOS8工作,因此如果有人有相同的问题,代码如下所示:

UIViewController *vc = [[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"myViewController"];

        vc.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
        vc.modalPresentationStyle = UIModalPresentationOverCurrentContext;

        [self vc animated:YES completion:nil]; 

对不起,我的帖子里没有信息。基本上,所有的触摸都通过我的视野,并击中了下面的场景。我想要的是捕捉视图上的触摸,而不是让它们通过下面的场景。您是否为覆盖UIView触摸开始等实现了触摸事件处理程序?jonogilmur:是的。我也试过UIGestureRecognitors。无法检测到我的触摸。@y0gie007我只能认为您的子视图可能被放置在场景后面。你能确认它确实在上面吗?