已解决:我是个彻头彻尾的白痴。我以前使用两个按钮(播放和暂停)并隐藏它们而不是更改一个按钮的图像。我愚蠢地忽略了这行代码:playButton.hidden = YES
.
我正在构建自定义控件MPMoviePlayerController
。我正在尝试将按钮的图像设置为pause.png
when MPMoviePlaybackState == MPMoviePlaybackStatePlaying
。否则,它应该设置为play.png
。这条语句每半秒运行一次,同样的方法 currentPlaybackTime
设置为 a UILabel
。
由于某种原因,它不会设置为pause.png
。按钮就消失了。虽然,条件记录Playing
并not playing
正确。
。H
@property (retain) UIImage *playBtnBG;
@property (retain) UIImage *pauseBtnBG;
.m
- (void)viewDidLoad
{
playBtnBG = [UIImage imageNamed:@"play.png"];
pauseBtnBG = [UIImage imageNamed:@"pause.png"];
}
- (void)updatePlaybackTime:(NSTimer*)theTimer
{
if (!sliding) {
int playbackTime = moviePlayer.currentPlaybackTime;
timeLabel.text = [NSString stringWithFormat:@"%d:%02d", (playbackTime / 60), (playbackTime % 60)];
playbackSlider.value = playbackTime;
}
if (moviePlayer.playbackState == MPMoviePlaybackStatePlaying) {
NSLog(@"Playing");
[playButton setImage:pauseBtnBG forState:UIControlStateNormal];
}
else {
NSLog(@"not playing");
[playButton setImage:playBtnBG forState:UIControlStateNormal];
}
}