在cocos2d-x中加入一个UIView,步骤如下:
1.在CCEGLView.h中添加代码
Cpp代码
1. void addSubView(void* uiView);
在CCEGLView.mm中实现
Cpp代码
void CCEGLView::addSubView(void* uiView)
{
[[EAGLView sharedEGLView] addSubview:(UIView*)uiView];
}
2.在需要调用的地方如下调用
Cpp代码
float screenWidth = CCDirector::sharedDirector()->getWinSize().width;
float screenHeight = CCDirector::sharedDirector()->getWinSize().height;
CGRect frame;
frame.origin.x = 0;
frame.origin.y = 0;
frame.size.width = screenWidth;
frame.size.height = screenHeight;
UIView *view = [[UIView alloc] initWithFrame:frame];
[view setUserInteractionEnabled:NO];
CCDirector::sharedDirector()->getOpenGLView()->addSubView(view);
[MBProgressHUD showHUDAddedTo:view animated:YES];//MBProgressHUD为开源的等待提示框
3.移除UIView只需要调用
Cpp代码
[view removeFromSuperview];
[view dealloc];