将UIView覆盖到Cocos层? [英] Overlaying a UIView onto a Cocos layer?

查看:167
本文介绍了将UIView覆盖到Cocos层?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是iOS和Cocos开发的新手。

I'm new to iOS and Cocos development.

我目前在HelloWorldLayer类中有一个基本的应用程序。它包含我的sprite和触摸交互的方法,一切都很好。

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层?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆