这种倒带方法适用于倒带按钮以及播放按钮。
-(void)rewind:(id)sender
{
[timer invalidate];
audioPlayer.currentTime = 0;
MainViewController *viewController = [[MainViewController alloc] init];
viewController.view.frame = CGRectMake(0, 0, 320, 480);
[self.view addSubview:viewController.view];
[self.view addSubview:toolbar];
[viewController release];
if([audioPlayer isPlaying])
{
[sender setImage:[UIImage imageNamed:@"Play Icon.png"] forState:UIControlStateSelected];
[audioPlayer pause];
[self pauseTimer];
[self pauseLayer:self.view.layer];
}else{
[sender setImage:[UIImage imageNamed:@"pause.png"] forState:UIControlStateNormal];
[audioPlayer play];
[self resumeTimer];
[self resumeLayer:self.view.layer];
if(isFirstTime == YES)
{
self.timer = [NSTimer scheduledTimerWithTimeInterval:11.0
target:self
selector:@selector(displayviewsAction:)
userInfo:nil
repeats:NO];
isFirstTime = NO;
}
}
}
现在在这种方法中,发送者是倒带按钮,播放/暂停的切换发生在倒带按钮上,而我希望这个切换播放按钮而不是发送者,它是倒带按钮。所以我尝试给出我想要切换的实际按钮的名称,并在我的代码中将该按钮定义为播放按钮,并且我在此倒带方法中添加了其操作方法。
这就是定义播放按钮的方式
//Add Play Button
UIButton *playButton = [UIButton buttonWithType:UIButtonTypeCustom];
[playButton addTarget:self action:@selector(playpauseAction:) forControlEvents:UIControlEventTouchUpInside];
playButton.frame = CGRectMake(0, 0, 30, 30);
[playButton setImage:[UIImage imageNamed:@"Play Icon.png"] forState:UIControlStateNormal];
[playButton setImage:[UIImage imageNamed:@"pause.png"] forState:UIControlStateSelected];
UIBarButtonItem *play = [[UIBarButtonItem alloc] initWithCustomView:playButton];
这是我在快退按钮中添加的播放按钮的方法
-(void)playpauseAction:(id)sender
{
if([audioPlayer isPlaying])
{
[sender setImage:[UIImage imageNamed:@"Play Icon.png"] forState:UIControlStateSelected];
[audioPlayer pause];
[self pauseTimer];
[self pauseLayer:self.view.layer];
}
else
{
[sender setImage:[UIImage imageNamed:@"pause.png"] forState:UIControlStateNormal];
[audioPlayer play];
[self resumeTimer];
[self resumeLayer:self.view.layer];
if(isFirstTime == YES)
{
self.timer = [NSTimer scheduledTimerWithTimeInterval:11.0
target:self
selector:@selector(displayviewsAction:)
userInfo:nil
repeats:NO];
isFirstTime = NO;
}
}
}
现在我现在面临的问题是,当我单击倒带按钮时,应该在播放按钮而不是倒带按钮上进行切换。
但是为了解决这个问题,我只是在这样的倒带方法中用 playButton 替换了 sender
[playButton setImage:[UIImage imageNamed:@"Play Icon.png"] forState:UIControlStateSelected];
但随后我收到红色警告消息,提示使用未声明的标识符 playButton。
我如何告诉倒带方法在 playButton 而不是倒带按钮上进行切换。
请帮忙。
谢谢。