2012-03-28 3 views

답변

4

다음, 당신이 사용하는 어떤 층의 헤더 파일에 opionsLayer.h

UISwitch *muteSwitch; 

을 UISwitch를 추가하여 층의하는 .m에 초기화 방법을 구현

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]; 

그런 다음 init 메소드가 아닌 .m에 콜백 함수를 추가하십시오.

- (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)를 사용하려고합니다. /). 그런데 필요한 것은 컨트롤을 회전시키는 것뿐입니다. 감사! –