- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在学习适用于 iOS 的 OpenGL ES 并在线学习 Ray Wenderlich 的教程。他做的第一件事是使用 OpenGL ES 2.0 将 View Controller 中的 View 设置为不同的颜色。所以我创建了一个名为 OpenGLView 的自定义类,它负责改变屏幕的颜色。然后在主 Storyboard中,我删除了 View Controller 中的原始 View ,并将其替换为 GLKView,并将其类设置为 OpenGLView。当我运行该项目时,一切正常。但现在我试图做同样的事情,除了 GLKView 在 UIView 内。像下面这样
当我在主 Storyboard 中将 GL View 的类设置为我的自定义类 OpenGlView 时,除了该类之外它没有。当我运行这个项目时,我看到的只是一个白屏。
如何将 GL View 设置为 OpenGLView 类?
编辑:
我相信它与应用程序委托(delegate)中的代码有关。
@interface AppDelegate : UIResponder <UIApplicationDelegate>{
OpenGLView* _glView;
}
@property (strong, nonatomic) UIWindow *window;
@property (nonatomic, retain) IBOutlet OpenGLView *glView;
@end
//In the implementation
@synthesize glView=_glView;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
CGRect screenBounds = [[UIScreen mainScreen] bounds];
self.glView = [[OpenGLView alloc] initWithFrame:screenBounds];
[self.window addSubview:_glView];
return YES;
}
最佳答案
您的代码在应用程序委托(delegate)中创建一个 glView 并将其添加为根窗口的 subview ;之后,通过 Storyboard 实例化 View Controller 并将其 View 添加到堆栈中。最后一个 View 是您看到的白色 View ,它覆盖了 glView。
为了更好地理解这种层次结构,您可以使用 Xcode Debug View Hierarchy 功能。
要解决您的问题,您可以删除 View Controller 或将 glView 作为 View Controller 的 subview 移动。
编辑:
如果您通过 Storyboard 创建 OpenGLView,initWithCoder
使用而不是initWithFrame
.将以下方法添加到 OpenGLView.m:
- (id)initWithCoder:(NSCoder *)decoder
{
self = [super initWithCoder:decoder];
if (self) {
[self setupLayer];
[self setupContext];
[self setupRenderBuffer];
[self setupFrameBuffer];
[self render];
}
return self;
}
关于ios - 无法在 UIView 中将自定义类设置为 GLKView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35873388/
从 iOS 11 开始,当我们在 GLKView 上调用显示方法时,我注意到 OpenGL-ES 崩溃。我们已确保 GLKView 和 EAGLContext 已正确实例化并从适当的线程调用。 下面是
我刚刚开始研究适用于 iOS 的 Open GL ES,我正在查看苹果模板代码上的源代码。问题是两个 - (void)glkView:(GLKView *)view drawInRect:(CGRec
当继承 GLKViewController 时,它有两个方法: - (void)update, 和- (void)glkView:(GLKView *)view drawInRect:(CGRect)
我的 iOS 应用程序窗口顶部的导航栏和底部的工具栏之间有一个 GLKView (OpenGL ES2.0)。我已经使用 UIPinchGestureRecognizer 实现了捏合缩放,但是当我缩小
我无法找到正确的位置来为使用 GLKView 和 GLKViewController 的 OpenGLES 应用程序进行着色器设置。 看起来 viewDidLoad 是一个很自然的地方,但是当我在这里
我使用外部渲染器创建应用程序以及如何按请求调用重绘?例如,在 Android 上,我可以使用 requestRenderer() 和 RENDERMODE_WHEN_DIRTY 渲染模式来完成此操作。
如果我 NSLog 我的 GLKView 类,我得到 GLKView 但为什么它没有可以分配给 EAGLContext 的上下文属性?为什么我必须将它转换为另一个变量,然后分配 EAGLContext
我正在开发 iPad OpenGL ES 2.0 应用程序,需要 1024x768 的后备帧缓冲区。我使用 GLKView 和 iOS 5.1 来管理后端帧/渲染缓冲区的创建(使用 XCode 提供的
如果我在界面生成器中创建 GLKView,我会看到几个与 gl 上下文相关的可配置属性(例如颜色格式)。如果我必须手动创建上下文,为什么还要存在这些属性? 最佳答案 颜色格式,无论是否有深度缓冲区等,
我正在尝试使用 GLKView 创建带有触摸输入的签名。但现在我需要一个 UIImage 位于签名下方。简而言之:我想使用自定义 GLKView 在 UIImage 上方绘制线条。 问题是我的线每次都
我有一个显示 CIFilter 的 CIImage 的 GLKView。当我通过捏合手势调整 View 框架大小时,我的帧率很低。这背后的问题是什么?我怎样才能适应它? 最佳答案 由于此 API 的工
我有一个基于“OpenGL 游戏”Xcode 模板的应用程序,用于日常测试/开发我想在模拟器中渲染全屏但分辨率较低(例如 1/2 或 1/4)。有什么有效/精明的方法来实现这一点? (如果有人想知道,
我很难找到任何示例来说明如何将 Core Image 与 GLKView 一起正确使用,以便顺畅地呈现 Core Image“配方”以响应用户输入。所以,看完Core Image Programmin
我遇到了这个异常: 2014-02-19 19:08:34.590 MyApp[42353:70b] *** Terminating app due to uncaught exception 'NS
当 GLKView 调整大小时,会在该 GLKView 的缓冲区和上下文中发生一些幕后操作。在执行这些幕后操作期间,绘制到 GLKView 不会产生正确的结果。 在我的场景中,我有一个启用了 setN
我正在尝试使用 GLKView 将图像放入 UITableViewCell 中以绘制图像。 我在 Storyboard中有一个原型(prototype)单元,其中有一个 GLKView。它没有选中启用
我正在学习 OpenGLES,我正在尝试将 GLKViewer 放入 UIViewController 中。 我知道我可以通过使用 GLViewController 来解决主要问题,但我正在努力学习如
我正在学习适用于 iOS 的 OpenGL ES 并在线学习 Ray Wenderlich 的教程。他做的第一件事是使用 OpenGL ES 2.0 将 View Controller 中的 View
我正在使用 GLKit 在 iPhone 上创建游戏。设置 GLKit 上下文并在其上绘制 Sprite 并不难,但是当我尝试向其添加文本时,这似乎是不可能的。我四处寻找答案,但我试图找到的所有解决方
我有一个 MainMenuViewController 和一个 GameViewController,它是一个 GLKViewConrtroller。 我第一次从主菜单转到 GameViewContr
我是一名优秀的程序员,十分优秀!