我已經編寫了下面的代碼來在標識符播放和暫停之間切換按鈕。該按鈕在暫停播放時必須是類型播放,並且在播放時必須暫停。UIBarButtonItem不能在Play和暫停之間切換
- (IBAction)playSound:(id)sender {
if (isPaused) {
playOrPauseButton = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemPause target:self action:@selector(pausePlaying)];
// playOrPauseButton.style = UIBarButtonSystemItemPause;
// [playOrPauseButton setStyle:UIBarButtonSystemItemPause];
isPaused = NO;
NSLog(@"Playing");
}
else {
playOrPauseButton = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemPlay target:self action:@selector(resumePlaying)];
// playOrPauseButton.style = UIBarButtonSystemItemPlay;
// [playOrPauseButton setStyle:UIBarButtonSystemItemPlay];
isPaused = YES;
NSLog(@"Paused");
}
}
評論性聲明是我從網上獲得的不同選項,我嘗試了一個接一個。三種選擇都沒有在播放和暫停狀態之間切換。我已將按鈕標識符設置爲在故事板中播放。無論我做什麼,按鈕仍然是播放按鈕。我能做些什麼來將按鈕切換爲播放/暫停類型?
對不起,我沒有得到你。我需要做的是將單個按鈕切換爲播放/暫停標識符,而不是添加兩個不同的按鈕來播放和暫停。 –