2010-05-03 33 views

回答

9

你不能直接添加一个UISlider作为一个图层/场景的cocos2d节点。

您必须将它作为子视图添加到您的cocos2d图层。这里是一个例子:

UISlider *sliderCtl = [[UISlider alloc] 
    initWithFrame:CGRectMake(170, 0, 125, 50)]; 

[sliderCtl addTarget:self action:@selector(sliderAction:) 
    forControlEvents:UIControlEventValueChanged]; 

sliderCtl.backgroundColor = [UIColor clearColor]; 
sliderCtl.value = 0; 

[[[[CCDirector sharedDirector] openGLView] window] 
    addSubview:sliderCtl]; 
1

对于更高版本的cocos2d,在下面的语句中不需要窗口。这支持自动转换。

[[[CCDirector sharedDirector] openGLView] addSubview:sliderCtl];