将 UIView 叠加到 Cocos 层上?

Overlaying a UIView onto a Cocos layer?(将 UIView 叠加到 Cocos 层上?)

本文介绍了将 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 层上?

基础教程推荐