我有一個UIButton,它具有與之關聯的UIButton顯示視圖,但不能切換到暫停按鈕
- 要播放的音頻文件
- 播放暫停按鈕之間切換
- 顯示視角的多個動作
如果我註釋掉displayViewAction:它工作正常(即播放音頻文件,也切換到暫停按鈕)。但是,如果我使用displayViewAction:方法播放音頻文件顯示視圖,但在顯示視圖之前應立即切換暫停按鈕的狀態,但不是。
代碼波紋管以供參考:
代碼的UIButton:
UIButton *playpauseButton = [UIButton buttonWithType:UIButtonTypeCustom];
[playpauseButton addTarget:self action:@selector(playpauseAction:) forControlEvents:UIControlEventTouchUpInside];
[playpauseButton addTarget:self action:@selector(displayviewsAction:) forControlEvents:UIControlEventTouchUpInside];
playpauseButton.frame = CGRectMake(0, 0, 50, 50);
[playpauseButton setImage:[UIImage imageNamed:@"play.png"] forState:UIControlStateNormal];
[playpauseButton setImage:[UIImage imageNamed:@"pause.png"] forState:UIControlStateSelected];
UIBarButtonItem *playpause = [[UIBarButtonItem alloc] initWithCustomView:playpauseButton];
代碼Playpause按鈕:
-(void)playpauseAction:(id)sender
{
if ([audioPlayer isPlaying]){
[sender setImage:[UIImage imageNamed:@"play.png"] forState:UIControlStateNormal];
[audioPlayer pause];
}
else {
[sender setImage:[UIImage imageNamed:@"pause.png"] forState:UIControlStateNormal];
[audioPlayer play];
}
}
代碼顯示視圖動作:
- (void)displayviewsAction:(id)sender
{
self.view = [[[UIView alloc] initWithFrame:[[UIScreen mainScreen] bounds]]autorelease];
[self.view setFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
PageOneViewController *viewController = [[[PageOneViewController alloc] init]autorelease];
[self.view addSubview:viewController.view];
}
燦任何人提醒我如何才能使它以這種方式工作?
以黃色獲取警告,表示實例方法playpauseAction未找到,並且displayviewsAction未找到 – user1120133 2012-02-06 17:27:21
仍然不能切換以立即暫停按鈕 – user1120133 2012-02-06 17:43:02
當然,您應該在頭文件中聲明您的playpauseAction。 – Martin 2012-02-07 10:22:31