Overlaying a UIView onto a Cocos layer?(将 UIView 叠加到 Cocos 层上?)
问题描述
我是 iOS 和 Cocos 开发的新手.
I'm new to iOS and Cocos development.
目前,我的 HelloWorldLayer 课程中有一个基本应用程序正在运行.它包含我的精灵和触摸交互方法,一切都很好.
I currently have a basic app going on in my HelloWorldLayer class. It contains my sprites and touch interaction methods and all is well.
我正在尝试在当前看到的内容之上添加另一个面板"(UIView?).最终,该面板将具有与主画布交互的按钮或其他东西.
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.
如何在画布屏幕上包含另一个 UIView?通过我的 appDelegate 或 HelloWorldLayer?
How can I include another UIView onto the canvas screen? Through my appDelegate, or my HelloWorldLayer?
谢谢
推荐答案
这是一种方法.我在这里使用了 UITextView,但您可以将这种方法用于 UIView 的任何后代.请记住,UIKit 的 y 坐标在屏幕左上角为零,而 Cocos2D 在左下角为零.
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];
或者,您可以尝试 Blue Ether 的 CCUIViewWrapper,存储库 这里.
Alternatively you could try Blue Ether's CCUIViewWrapper, repository here.
这篇关于将 UIView 叠加到 Cocos 层上?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:将 UIView 叠加到 Cocos 层上?
基础教程推荐
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01
- android 应用程序已发布,但在 google play 中找不到 2022-01-01
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01
- 如何在 UIImageView 中异步加载图像? 2022-01-01
- Android:对话框关闭而不调用关闭 2022-01-01