0

我正在制作类似于 ruzzle 的东西,为了在字母(按钮)之间滑动,我正在使用触摸事件(touchBegan、、、touchMovetouchEnded

该应用程序由二合一view controllers组成storyboardstoryboard第一个用于主菜单,第二个用于游戏内屏幕,我使用id在它们之间切换。一切正常,直到您从 inGame 视图切换到 MainMenu 视图。

问题是当您从 inGame 屏幕返回主菜单时,触摸事件仍处于活动状态,这是一个问题,因为当您触摸屏幕上的任何位置时,应用程序会崩溃。发生这种情况是因为出于某种原因从 MainMenu 视图调用了 inGame 视图中的方法。有没有办法只限制inGameView的触摸事件?

PS。在我的情况下,该setUserInteraction:(BOOL)方法不是一个选项,因为您不能再按主菜单中的按钮。

从 MainMenu 移动到 inGame

GamePlayView *gpv = [self.storyboard instantiateViewControllerWithIdentifier:@"GamePlayView"];
[self presentViewController:gpv animated:YES completion:nil];

并从 inGame 到 MainMenu 与

ViewController *svc = [storyboard instantiateViewControllerWithIdentifier:@"ViewController"];
[self presentViewController:svc animated:YES completion:nil];
4

2 回答 2

0

The problem is that each time you presentViewController:animated:completion: the previous view controller still exists 'under' the new view controller. If your top presented view controller isn't handling / blocking all touches then they will be passed on to other views / controllers in the responder chain.

From the main view you could continue to use presentViewController:animated:completion:. But to get from the game view back to the menu you should use dismissViewControllerAnimated:completion: . This will remove the game view controller from the screen (and destroy the instance) so it doesn't continue to take up resources or handle touches.

于 2013-08-31T14:14:47.557 回答
0

I don't think your problem is related to touch events. Each time you switch view controllers you're creating a new view controller. Seems more likely that when you move from the game to the menu you should simply dismiss the game controller, allowing the existing main controller to be displayed again.

于 2013-08-31T14:15:12.137 回答