views:

19

answers:

2

I've got a problem thats been perplexing me for a while. I have a custom control for the iPhone sdk. When the user touches the control I want to draw a small bubble above the users touch position with some information in it. A bit like a thought bubble in a cartoon.

Initially I've done it by adding a UIView subview to the control. However if I use the control where I don't have control of the z-order, for example in a table view, then the bubble will be drawn under other controls.

I've looked around but I'm not sure how to approach this problem. Everything I've read seems to indicate that you need to know the tree structure of the controls. Ideally I'd like to apply it to some layer that sits over the window as a whole, but I'm not sure how. I've also look at core graphics but cannot see any obvious answers.

Does anyone have any ideas of perhaps something they can point me at which will help.

Thanks

+1  A: 

If you want to add a UIView to the 'top window', you can use the application UIWindow for that.

UIWindow is a subclass of UIView, so you can just use - (void)addSubview:(UIView *)view to add the new view to the window.

[[UIApplication sharedApplication] keyWindow] addSubview:yourView];
Rengers
Thanks, that seems to have done the trick. I just need to adjust the positioning now because it's no longer in relation to the control, but to the window ;-)
Derek Clarkson
A: 

You could try adding it as a subview of the window, though, I don't think that's the most appropriate solution.

Personally, I would add my control as a subview to whichever view (maybe a table cell) and then tell that view to bring your control to the front.

[tablecell bringSubviewToFront:myControl];

That way, when you display your bubble, it'll be on top.

Jasarien