0

我在我的 cocos2d 项目中使用 UISwitch,如下所示:

//header file

UISwitch    *musicCtrl;

//implementation file


        musicCtrl = [[UISwitch alloc] initWithFrame:CGRectMake(100, 50, 0, 0)];
        musicCtrl.on = YES;
        [musicCtrl addTarget:self action:@selector(musicOnOff) forControlEvents:UIControlEventValueChanged];
        [[[CCDirector sharedDirector]openGLView] addSubview:musicCtrl];
        musicCtrl.transform = CGAffineTransformMakeRotation(M_PI/2);
        [musicCtrl release];

我已将 UISwitch 附加到 openGLView,但我需要能够将其附加到 GLView 上的某个 CCLayer。那可能吗?我似乎找不到 cocos2d 的 UISwitch 替代品。

4

1 回答 1

0

这是不可能的。

您只能将 UIKit 视图添加到 cocos2d 视图或主窗口。无论哪种方式,UIKit 视图都将绘制在所有 cocos2d 节点之上。您不能将 UIKit 视图添加到特定层。

具体来说,您不能以某些 cocos2d 节点绘制在 UIKit 视图前面而其他节点绘制在 UIKit 视图后面的方式将 UIKit 视图添加到 cocos2d 应用程序。那是不可能的。

于 2013-01-04T12:35:50.337 回答