Old question title: How to capture events in parent UIViews, such as HUD layers?
I am attempting to write a game using the UI framework rather than cocos2d.
I would like to make View partials with all their events handled properly. It does not seem possible.
By partial views, I refer to the way Ruby on Rails (and other languages) allows you to have small chunks of a presentation layer (view code) that appear in a larger piece of a presentation layer (view code).
The game has a HUD layer with score at the top (and other meta data) and I use
[self.view addSubview:y]
or
[self.navigationController push...]
Visually, it would be like this (not to scale):
+----------------------------+
|A |
|+--------+ +------------+ |
||B | |C | |
|| | | | |
|+--------+ | | |
| | | |
| +------------+ |
+----------------------------+
- Section A has buttons relating to main menu (primary navigation)
- Section B has buttons for score, etc
- Section C is the main game area
Both Section A and Section B are HUD layers, they are meant to have clickable events where required.
I do not want to keep repeating the same code over and over again, so I feel a HUD system where I include the views I want in the window should be the best way to accomplish this.
The problem I am having is that if I include my HUD.h/HUD.m file in any other View controller, I can no longer accept the clicks for Sections A or B in Section C, and I cannot make it perform event actions as it always complains that the method doesn't exist within Section C.
If I am on the Section C view I should accept clicks from A and B and handle them appropriately.
Thus, what is the best way to capture events via a HUD layering system, and handle the events appropriately?
The closest I've seen is possibly using touchesBegan but what I am not clear on is how to link touchesBegan events to events that are in Section A/B's controller.
Thanks.
I've decided having tested several different ideas to go with cocos2d as it would be a good thing to add to my skillset.
Closed.