0
好夥計我遇到了UIButton的問題,也許這很容易解決。我有一個帶有IBAction toggleMusic的按鈕,用於更改背景圖像。UIButton setBackgroundImage and viewWillAppear
-(IBAction)toggleMusic{
if (gameAppDelegate.playMusic) {
gameAppDelegate.playMusic = NO;
[menuAudioPlayer stop];
[botaoMusic setBackgroundImage:[UIImage imageNamed:@"bt_sound_off.png"] forState:UIControlStateNormal];
[SoundManager playSoundFile:@"botao3" Format:@"wav" InLoop:NO];
}
else {
gameAppDelegate.playMusic = YES;
[menuAudioPlayer play];
[botaoMusic setBackgroundImage:[UIImage imageNamed:@"bt_sound_on.png"] forState:UIControlStateNormal];
[SoundManager playSoundFile:@"botao3" Format:@"wav" InLoop:NO];
}
}
這工作正常。 playmusic(布爾)是一個存儲變量,所以每次關閉應用程序後,應用程序就知道它是否應該播放音樂。這也工作正常。
問題是,我想在應用程序打開時(不僅在單擊按鈕時)立即設置正確的背景圖像(音樂開/關)。所以我把視圖下面的代碼將出現:
-(void)viewWillAppear:(BOOL)animated{
if(gameAppDelegate.playMusic)
[botaoMusic setImage:[UIImage imageNamed:@"bt_sound_on.png"] forState:UIControlStateNormal];
else
[botaoMusic setImage:[UIImage imageNamed:@"bt_sound_off.png"] forState:UIControlStateNormal];
}
,當我介紹這個代碼,應用程序成功地識別出正確的背景圖像的觀點出現時,但togglemusic不再改變按鈕的背景,當我觸摸按鈕。這可能是一些愚蠢的,但我不能找出I'm做錯了......
THX that's它被裝!問題解決了 – user1347271