2012-03-28 77 views

回答

4

一個UISwitch添加到任何您層使用的頭文件,

opionsLayer.h

UISwitch *muteSwitch; 

然後在層的.M實現它在你的init方法

muteSwitch = [[ UISwitch alloc ] initWithFrame: CGRectMake(100, 50, 0, 0) ]; 
muteSwitch.on = YES; 
[muteSwitch addTarget:self action:@selector(soundOnOrOff:) forControlEvents:UIControlEventValueChanged]; 
[[[CCDirector sharedDirector] openGLView] addSubview:muteSwitch]; 
[muteSwitch release]; 

然後在.m中添加回調函數但不在init方法中,

- (void)soundOnOrOff:(id)sender 
{ 

    if ([[SimpleAudioEngine sharedEngine] mute]) { 
     // This will unmute the sound 
     [[SimpleAudioEngine sharedEngine] setMute:0]; 
    } 
    else { 
     //This will mute the sound 
     [[SimpleAudioEngine sharedEngine] setMute:1]; 
    } 

} 

假設您在這裏使用簡單的音頻引擎,但是.. 因此您必須在標頭中導入SimpleAudioEngine

+0

它適用於Apple標準的UISwitch控制,但我試圖使用[自定義UISwitch](http://www.catamount.com/blog/1063/uicustomswitch-customizing-uiswitch-color-it-change-labels /)。順便提一下,唯一需要的是旋轉控制。謝謝! – 2012-03-29 13:35:22