我的 UIView 在视频下方有 2 个按钮,一个播放和一个停止按钮。单击播放按钮时,结果是暂停按钮,反之亦然。这是实现代码:
-(UIView *)subViewControlsView{
UIView *subViewWithControls = [[[UIView alloc]init]autorelease];
subViewWithControls = [[UIView alloc]initWithFrame:CGRectMake((self.view.frame.size.width - xPoint_Pad) - 147, 630, 147, 44)];
[subViewWithControls setBackgroundColor:[UIColor clearColor]];
playButton = [UIButton buttonWithType:UIButtonTypeCustom];
[playButton setFrame:CGRectMake(0, 0, 44, 44)];
[playButton setImage:[UIImage imageNamed:@"play.png"] forState:UIControlStateNormal];
[playButton setImage:[UIImage imageNamed:@"pause.png"] forState:UIControlStateSelected];
[playButton addTarget:self action:@selector(play:) forControlEvents:UIControlEventTouchUpInside];
[subViewWithControls addSubview:playButton];
stopButton = [UIButton buttonWithType:UIButtonTypeCustom];
[stopButton setFrame:CGRectMake(94, 0, 44, 44)];
[stopButton setImage:[UIImage imageNamed:@"stop.png"] forState:UIControlStateNormal];
[stopButton addTarget:self action:@selector(stop:) forControlEvents:UIControlEventTouchUpInside];
[subViewWithControls addSubview:stopButton];
return subViewWithControls;
}
这是播放按钮操作:
-(void)play:(UIButton *)sender
{
if(sender.selected == NO){
sender.selected = YES;
[self setButtonCurrentState:YES];
[self.moviePlayerController setInitialPlaybackTime:self.currentTime];
[self playMovieFile:[self localMovieURL]];
}
else{
sender.selected = NO;
[self setButtonCurrentState:NO];
self.currentTime = self.moviePlayerController.currentPlaybackTime;
[self.moviePlayerController pause];
}
}
我的要求是,一旦视频停止,即当用户单击停止按钮时,我需要将播放图像更改为暂停播放按钮。我尝试了以下方法:
-(void)stop:(UIButton *)sender{
if (self.buttonCurrentState == YES)
{
[playButton setImage:[UIImage imageNamed:@"play.png"] forState:UIControlStateNormal];
}
self.currentTime = 0.0;
[[self moviePlayerController] stop];
[self deletePlayerAndNotificationObservers];
}
它正在验证停止按钮操作中的条件,我已经调试和测试过,但是图像更改不影响。想知道为什么?
我也尝试在播放按钮操作中更改图像,而不是在方法中进行。-(UIView *)subViewControlsView
但令我惊讶的是,我看不到按钮,因为图像未在视图方法中设置。我尝试设置图像作为播放最初用于控制状态正常,然后改变播放动作。现在发生的是播放按钮没有变成暂停按钮,这是一个双重打击。我尝试设置标签,布尔值等等。没有一个似乎工作!
任何人都可以建议我一个解决方案吗?
提前谢谢大家:)