简体   繁体   English

在UIView或CALayer中显示CAEAGLLayer

[英]Displaying CAEAGLLayer in a UIView or CALayer

Rather new to trying to get OpenGL ES working on the iPhone, but I've created a working demo from an OpenGL template and wanted to add it to another App which is a standard UIViewController App. 尝试使OpenGL ES在iPhone上运行并不是什么新事物,但是我已经从OpenGL模板创建了一个有效的演示,并将其添加到另一个应用程序中,该应用程序是标准的UIViewController应用程序。 After searching around it seems that I can't addSubview a CAEAGLLayer to a CALayer aka UIView. 经过搜索后,似乎无法将CAEAGLLayer的Subview添加到CALayer aka UIView。 How would I go about doing this? 我将如何去做呢? Or am I completely wrong in what I'm doing. 还是我在做什么完全错误。

Cheers for any help 为任何帮助加油

Simply use a UIView and add: 只需使用UIView并添加:

+ (Class)layerClass {
    return [CAEAGLLayer class];
}

That UIView is now a CAEAGLLayer, so you can add that view as a subview of another UIView like normal. 该UIView现在是CAEAGLLayer,因此您可以像平常一样将该视图添加为另一个UIView的子视图。

What I actually had to do was change in the EAGLView -initWithCoder to -initWithFrame and make the appropriate changes to the method to handle the frame. 我实际上要做的是将EAGLView -initWithCoder更改为-initWithFrame,并对处理框架的方法进行了适当的更改。 Once I did that and initialised the view with initWithFrame it worked. 一旦完成此操作,并使用initWithFrame初始化视图,便可以正常工作。

我相信您正在寻找CALayer的insertSublayer方法或addSublayer方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM