11

I'm having some troubles adding an UIView to cocos2d v2.0 since the openGlView is deprecated I can't add the view to it. I was looking around to find another way to do this but I couldn't find anything.

Can anyone tell me the new way to add an UIView in front of all cc layers?? or how can I accomplish this?

Josh Crozier
  • 233,099
  • 56
  • 391
  • 304
Rafael Jimeno
  • 626
  • 2
  • 8
  • 20

2 Answers2

28

Use this instead of openGLView:

[[CCDirector sharedDirector] view];
SimplyKiwi
  • 12,376
  • 22
  • 105
  • 191
  • hey thanks for your reply, but I don't think I can use this. What I want is to add a custom keyboard wich is a subclass of UIView into my main layer (CCLayer). I currently have the deprecated method working but I want to remove all warnings. – Rafael Jimeno Jun 12 '12 at 19:19
  • 1
    Just add the UIView to the window then, that would be the easiest way. If that doesn't work I think there are other workarounds for adding UIViews. – SimplyKiwi Jun 12 '12 at 19:27
  • but to access the window I need to use openGlView which is deprecated. Guess I'll keep looking. Thank you XD – Rafael Jimeno Jun 12 '12 at 19:39
  • 1
    Also ccGLView is the new API for openGLView so this is specifically what you are looking for. – SimplyKiwi Jun 12 '12 at 20:06
  • But what if you want to bring cocos2d view to the front? how would you accomplish that? – Juan Boero May 29 '15 at 05:23
  • @JuanPabloBoero Not sure what you mean. Its the same as before just reference the view using CCDirector's view and just make your other subviews all behind that. – SimplyKiwi May 29 '15 at 06:04
3

This worked for me!

[[[CCDirector sharedDirector] view] addSubview:myUiView];

Considering that openGLView is deprecated!

Sagar
  • 555
  • 9
  • 24