iOS 7+ 中如何让 cocos2d-x 游戏一直显示 [白底黑字] 的状态条? - V2EX
V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
iOS 开发实用技术导航
NSHipster 中文版
http://nshipster.cn/
cocos2d 开源 2D 游戏引擎
http://www.cocos2d-iphone.org/
CocoaPods
http://cocoapods.org/
Google Analytics for Mobile 统计解决方案
http://code.google.com/mobile/analytics/
WWDC
https://developer.apple.com/wwdc/
Design Guides and Resources
https://developer.apple.com/design/
Transcripts of WWDC sessions
http://asciiwwdc.com
Cocoa with Love
http://cocoawithlove.com/
Cocoa Dev Central
http://cocoadevcentral.com/
NSHipster
http://nshipster.com/
Style Guides
Google Objective-C Style Guide
NYTimes Objective-C Style Guide
Useful Tools and Services
Charles Web Debugging Proxy
Smore
xpol
V2EX    iDev

iOS 7+ 中如何让 cocos2d-x 游戏一直显示 [白底黑字] 的状态条?

  •  
  •   xpol 2015-11-26 14:49:02 +08:00 2279 次点击
    这是一个创建于 3684 天前的主题,其中的信息可能已经有所发展或是发生改变。

    需求

    我现在需要让我的 cocos2d-x 游戏一直显示白底黑字的状态条。

    实现

    根据这篇文章,我的做法如下:

    Info.plist

    • View controller-based status bar appearance NO
    • Status bar is initially hidden NO
    • Status bar style Gray style (default)

    AppController.mm

    frameworks/runtime-src/proj.ios_mac/ios/AppController.mm 中的 application:didFinishLaunchingWithOptions: 添加如下代码(完整代码见后面)。

    [[UIApplication sharedApplication].statusBarStyle:UIStatusBarStyleDefault]; [[UIApplication sharedApplication] setStatusBarHidden:NO]; // The OpenGLWindow _window = [[UIWindow alloc] initWithFrame: [[UIScreen mainScreen] applicationFrame]]; 

    RootViewController.mm

    - (BOOL)prefersStatusBarHidden { return NO; } - (UIStatusBarStyle)preferredStatusBarStyle { return UIStatusBarStyleDefault; } 

    问题

    由于上提到的参考 文章 是显示的黑底白字的状态条,然而我的需求是白底黑字
    最终产生的结果如下:

    StatusBar

    上面的黑色部分其实就是状态条,只是背景(由于窗口被下移,没有绘制那块区域)也是黑色的,所以就黑成一团了。

    cocos2d-x 提供的模板,是这样创建 _window 的:

    _window = [[UIWindow alloc] initWithFrame: [[UIScreen mainScreen] bounds]];

    我根据上面的文章,将窗口下移,我修改后的代码:

    _window = [[UIWindow alloc] initWithFrame: [[UIScreen mainScreen] applicationFrame]];

    UI 是这样的结构(完整代码见『附』):

    如上图,黄色为标识区域为 StatusBar
    红色标识区域为_window
    _window 内部为 [_window]---rootViewController--> [viewController] ---view--> [eaglView]

    eaglView 是最终 cocos2d-x 绘图的区域,他填满整个 _window

    现在我想要的结果是让上图的黑色区域底色变成白色,由于我不懂 iOS ,我猜想的方案可能是:

    • applicationFrame 创建窗口;新加一个和 _window 平级的白色 UIView ,放到黑色区域。
    • 或者用 bounds 创建窗口,弄一个固定高度为 StatusBar 高度的 UIView 将 eaglView 『挤』下去。
    • 或者能不能设置整个应用的底色为白色?

    大致就是这些,请大家指点下我,最好有代码。我不熟悉 iOS 开发。

    感谢了!

    application:didFinishLaunchingWithOptions 完整代码:

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { cocos2d::Application *app = cocos2d::Application::getInstance(); app->initGLContextAttrs(); cocos2d::GLViewImpl::convertAttrs(); // Override point for customization after application launch. [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault animated:YES]; [[UIApplication sharedApplication] setStatusBarHidden:NO]; // Add the view controller's view to the window and display. _window = [[UIWindow alloc] initWithFrame: [[UIScreen mainScreen] applicationFrame]]; CCEAGLView *eaglView = [CCEAGLView viewWithFrame: [self.window bounds] pixelFormat: (NSString*)cocos2d::GLViewImpl::_pixelFormat depthFormat: cocos2d::GLViewImpl::_depthFormat preserveBackbuffer: NO sharegroup: nil multiSampling: NO numberOfSamples: 0 ]; [eaglView setMultipleTouchEnabled:YES]; // Use RootViewController manage CCEAGLView viewCOntroller= [[RootViewController alloc] initWithNibName:nil bundle:nil]; viewController.wantsFullScreenLayout = YES; viewController.view = eaglView; // Set RootViewController to window if ( [[UIDevice currentDevice].systemVersion floatValue] < 6.0) { // warning: addSubView doesn't work on iOS6 [self.window addSubview: viewController.view]; } else { // use this method on ios6 [_window setRootViewController:viewController]; } [_window makeKeyAndVisible]; // IMPORTANT: Setting the GLView should be done after creating the RootViewController cocos2d::GLView *glview = cocos2d::GLViewImpl::createWithEAGLView(eaglView); cocos2d::Director::getInstance()->setOpenGLView(glview); app->run(); return YES; } 
    目前尚无回复
    关于     帮助文档     自助推广系统     博客     API     FAQ     Solana     2769 人在线   最高记录 6679       Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 33ms UTC 08:00 PVG 16:00 LAX 00:00 JFK 03:00
    Do have faith in what you're doing.
    ubao msn snddm index pchome yahoo rakuten mypaper meadowduck bidyahoo youbao zxmzxm asda bnvcg cvbfg dfscv mmhjk xxddc yybgb zznbn ccubao uaitu acv GXCV ET GDG YH FG BCVB FJFH CBRE CBC GDG ET54 WRWR RWER WREW WRWER RWER SDG EW SF DSFSF fbbs ubao fhd dfg ewr dg df ewwr ewwr et ruyut utut dfg fgd gdfgt etg dfgt dfgd ert4 gd fgg wr 235 wer3 we vsdf sdf gdf ert xcv sdf rwer hfd dfg cvb rwf afb dfh jgh bmn lgh rty gfds cxv xcv xcs vdas fdf fgd cv sdf tert sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf shasha9178 shasha9178 shasha9178 shasha9178 shasha9178 liflif2 liflif2 liflif2 liflif2 liflif2 liblib3 liblib3 liblib3 liblib3 liblib3 zhazha444 zhazha444 zhazha444 zhazha444 zhazha444 dende5 dende denden denden2 denden21 fenfen9 fenf619 fen619 fenfe9 fe619 sdf sdf sdf sdf sdf zhazh90 zhazh0 zhaa50 zha90 zh590 zho zhoz zhozh zhozho zhozho2 lislis lls95 lili95 lils5 liss9 sdf0ty987 sdft876 sdft9876 sdf09876 sd0t9876 sdf0ty98 sdf0976 sdf0ty986 sdf0ty96 sdf0t76 sdf0876 df0ty98 sf0t876 sd0ty76 sdy76 sdf76 sdf0t76 sdf0ty9 sdf0ty98 sdf0ty987 sdf0ty98 sdf6676 sdf876 sd876 sd876 sdf6 sdf6 sdf9876 sdf0t sdf06 sdf0ty9776 sdf0ty9776 sdf0ty76 sdf8876 sdf0t sd6 sdf06 s688876 sd688 sdf86