Overlaying a UIView onto a Cocos layer?
I’m new to iOS and Cocos development.
I currently have a basic app going on in my HelloWorldLayer class. It contains my sprites and touch interaction methods and all is well.
I’m trying to add another “panel” (UIView?) over top of what is currently seen. Eventually this panel will have buttons or other things that will interact with the main canvas.
How can I include another UIView onto the canvas screen? Through my appDelegate, or my HelloWorldLayer?
Solutions Collect From Internet About “Overlaying a UIView onto a Cocos layer?”
Here is one way to do it. I’ve used UITextView here but you could use the approach for any descendant of UIView. Bear in mind that UIKit’s y coordinate is zero at the top-left of the screen, whereas Cocos2D’s is zero at the bottom left.
// Make your subview UITextView* t = [[UITextView alloc] initWithFrame: CGRectMake(10, 10, 200, 200)]; t.backgroundColor = [UIColor blackColor]; t.textColor = [UIColor whiteColor]; t.text = @"Hello UIKit!"; t.editable = NO; // Add it as a subview of the Cocos2D view UIView* cocosView = [[CCDirector sharedDirector] openGLView]; [cocosView addSubview:t];
Alternatively you could try Blue Ether’s CCUIViewWrapper, repository here.
- Can't convert from NSString to NSDate
- Why isn't guard let foo = foo valid?
- If arrays are value types and therefore get copied, then how are they not thread safe?
- Communication between two applications
- What is causing this Crashlytics compile warning? (Auto-Linking supplied '…' framework linker option at '…' is not a dylib)
- In Swift, what does the ! symbol mean in a function signature?
- How to Completely Uninstall Xcode and Clear All Settings
- Double question mark, How does it work?
- Statically link OpenSSL in XCode
- Facebook Login Swift iOS 10 – Nothing Works
- Are there strongly-typed collections in Objective-C?
- Saving Already Created Live Photos
- UIScrollview animation depending on content offset
- Xcode and XIB self documentation
- Xcode 4.4.1, iOS 5.1: Xcode cannot run using the selected device