再次调用addsubview导致速度变慢

发布于 2024-08-31 23:07:21 字数 1093 浏览 8 评论 0原文

我正在为 iPhone 编写一个小音乐游戏。我快完成了,这是阻止我推出它的唯一问题。非常感谢任何解决此问题的帮助。

这就是我所做的: 在我的 appDelegate 中,我将菜单视图屏幕添加到窗口中。菜单视图屏幕充当容器并控制向用户呈现哪个视图。

意思是,在菜单视图屏幕上我有 4 个按钮(新游戏、选项、常见问题解答、高分)。 当用户单击按钮时,会发生以下情况:

 if (self.gameViewController == nil)
 {
  GameViewController *viewController = [[GameViewController alloc] initWithNibName:@"GameViewController" bundle:nil];
  self.gameViewController = viewController;
  [viewController release];
 }
 [self.view addSubview:self.gameViewController.view];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleSwitchViewNotificationFromGameView:) name:@"SwitchView" object:gameViewController];

当用户返回菜单时,这段代码将被执行:

 [[NSNotificationCenter defaultCenter] removeObserver:self];
 [self.gameViewController viewWillDisappear:YES];
 [self.gameViewController.view removeFromSuperview];

这适用于所有屏幕,但不适用于游戏屏幕(这是唯一一个有大量用户的屏幕)相互作用) 意味着 iPhone 的响应速度(播放铃声时)变得非常慢。 当我第一次显示游戏视图时,性能很好。当我再次将其添加到菜单视图容器子视图(addsubview)时,它开始变慢(基本上打开一个新游戏) 有什么想法导致(或解决)这个问题吗?

非常感谢

最好的问候 汤姆

i am writing a little music-game for the iphone. I am almost done, this is the only issue which keeps me from rolling it out. any help to solve this is much appreciated.

this is what i do:
at my appDelegate I add my menu-view-screen to the window. the menu-view-screen acts as a container and controls which view gets presented to the user.

means, on the menu-view-screen I got 4 buttons (new game, options, faq, highscore).
when the user clicks on a button something as this happens:

 if (self.gameViewController == nil)
 {
  GameViewController *viewController = [[GameViewController alloc] initWithNibName:@"GameViewController" bundle:nil];
  self.gameViewController = viewController;
  [viewController release];
 }
 [self.view addSubview:self.gameViewController.view];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleSwitchViewNotificationFromGameView:) name:@"SwitchView" object:gameViewController];

when the user returns to the menu, this piece of code gets executed:

 [[NSNotificationCenter defaultCenter] removeObserver:self];
 [self.gameViewController viewWillDisappear:YES];
 [self.gameViewController.view removeFromSuperview];

this works fine for all screens but not for the gamescreen(well this is the only one with heaps of user-interaction)
means the responsiveness of the iphone(when playing tones) gets really slow.
The performance is fine when I display the gameview for the first time. it starts getting slower as soon as I add it to the menu-views-container-subviews again (addsubview) (basically open up a new game)
any ideas what causes(or to get around) this?

thanks heaps

Best regards
Tom

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

究竟谁懂我的在乎 2024-09-07 23:07:21

好吧,从我的角度来看,这听起来不像是控制器问题。这听起来像是其他东西正在运行或占用内存的问题。我建议使用分析工具来查看是否可以查明 CPU 消失的位置。例如,您可能会遇到正在执行大量操作的对象的内存泄漏。

Ok, off the top of my head this doesn't sound like a controller issue. It sounds like an issue with something else being left running or chewing up memory. I'd suggest using the profiling tools to see if you can pin point where the CPU is disappearing too. You might have a memory leak of objects which are also doing lots of stuff for example.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文