iphone - 通过 Storyboard添加 subview 而不是手动添加 subview ?

标签 iphone objective-c ios xcode storyboard

我对带有 Storyboard的 x 代码的 subview 有一个小问题。

我想用球做一些小应用。你必须点击它们,它们就会消失。 我还想要一个暂停菜单。

所以我制作了一个带有 1 个 View (一般 View )、1 个 subview (暂停菜单)的 viewController,用 Storyboard制作(所以我在代码中看不到它们)

我想在这个 viewController 中有一个 EAGLView 所以我这样做了:

self.director = [CCDirector sharedDirector];
self.myglView = [EAGLView viewWithFrame:CGRectMake(0, 60, 320, 420)
                                pixelFormat:kEAGLColorFormatRGBA8
                                depthFormat:0       
                         preserveBackbuffer:NO
                                 sharegroup:nil
                              multiSampling:NO
                            numberOfSamples:0                   ];
}

[self.director setOpenGLView:self.myglView];

glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
glClearColor(0.0, 0.0, 0.0, 0.0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

self.myglView.opaque = NO;
self.myglView.backgroundColor = [UIColor clearColor];
[self.view addSubview:self.myglView];

我在这个eaglview中创建的2D世界中添加了一些 body (球),这是有效的,但现在当我想暂停游戏时。

我用这个“弹出”暂停菜单:

self.pauseView.hidden = false;

出现暂停菜单,但所有球都在暂停菜单上:/

有人看到我的问题是什么吗? ^^' 是否有诸如图层或优先级 subview 之类的东西?

非常感谢您的阅读和帮助我:)

最佳答案

如果您在 Storyboard 中添加暂停 View ,那么它将在加载 View 时添加,即在您实际添加 EAGLView 之前。添加 subview 就像将乐高积木相互堆叠一样。最后添加的一项位于顶部。

您应该能够在暂停 View 下方添加 EAGLView,如下所示:

[self.view insertSubview:self.myglView belowSubview:self.pauseView];

关于iphone - 通过 Storyboard添加 subview 而不是手动添加 subview ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10519216/

相关文章:

ios - React Native iOS 应用程序在使用 xcode 9.0 的 iOS 11.3 上崩溃 "EXC_BREAKPOINT (SIGTRAP)"

ios - UITableViewController 自定义单元格中缺少 UIButton 默认点击淡入淡出动画

Objective-C 使用动态绑定(bind),但是如何呢?

ios - 使用 Antair Cordova SQLitePlugin 的 Ionic 预填充数据库 [帮助请求]

iphone - iOS 5、Xcode 4.2 和 ProtoBuf

ios - MPNowPlayingInfoCenter 和 MPRemoteCommandCenter 在模拟器中工作,但在设备上不起作用

iphone - Xcode:+CoreDataProperties.swift 问题

ios - 使用 ReactiveCocoa 跟踪远程对象的 UI 更新

iphone - 如何从 NSXMLParserdelegate 方法返回 tableview 的行计数?

iphone - 使用 CFDictionaryCreate 和特殊字符创建 CFDictionaryRef