ビデオの下にある 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が、驚いたことに、ビューメソッドで画像が設定されていないため、ボタンが表示されません。コントロール状態の通常の最初の再生としての画像、次に再生アクションの変更.今何が起こるかは、再生ボタンが一時停止ボタンに変わらないことです.これは二重の打撃です.タグ、ブール値などを設定しようとしました.それらのどれも動作するようです!!!
誰でも私に解決策を提案してもらえますか?
よろしくお願いします:)