質問

私は自分のアプリケーションにイントロムービーを再生するにはMPMoviePlayerを設定しています。それはちょうど素晴らしい作品、唯一の問題は、それが14秒間続き、私は私のユーザーの映画のどこかを押して、イントロをスキップするチャンスを与えたいということです。

、それらを必要としないように私は、映画のコントロールを非表示になっています。

コード:

NSString *introPath = [[NSBundle mainBundle] pathForResource:@"intro" ofType:@"mov"];
intro = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL fileURLWithPath:introPath]];
[intro setMovieControlMode:MPMovieControlModeHidden];
[intro play]; 

ありがとうございます!

役に立ちましたか?

解決

編集:私の最初のソリューションが動作しません、映画は第二のウィンドウに表示されているので、(それがiPhone上のビュー階層に複数のウィンドウを持っていることは非常に稀です)アプリのメインウィンドウの上に重ね。 AppleののMoviePlayerサンプルコードに基づいてこのソリューションでは、作業を行います:

. . .
    // assuming you have prepared your movie player, as in the question
    [self.intro play];

    NSArray* windows = [[UIApplication sharedApplication] windows];
    // There should be more than one window, because the movie plays in its own window
    if ([windows count] > 1)
    {
        // The movie's window is the one that is active
        UIWindow* moviePlayerWindow = [[UIApplication sharedApplication] keyWindow];
        // Now we create an invisible control with the same size as the window
        UIControl* overlay = [[[UIControl alloc] initWithFrame:moviePlayerWindow.frame]autorelease];

        // We want to get notified whenever the overlay control is touched
        [overlay addTarget:self action:@selector(movieWindowTouched:) forControlEvents:UIControlEventTouchDown];

        // Add the overlay to the window's subviews
        [moviePlayerWindow addSubview:overlay];
    }
. . .

// This is the method we registered to be called when the movie window is touched
-(void)movieWindowTouched:(UIControl*)sender
{
    [self.intro stop];
}

NB:あなたはインスタンス変数のムービープレイヤーへの参照を保存する必要があり、そしてそれは我々がそれにアクセスするために使用できるプロパティを宣言するのが最も便利です。例の使用self.introだけではなくintroである理由です。あなたはインスタンス変数とプロパティを宣言する方法がわからない場合は、他の場所でこのサイトとの情報の多くがあります。

BELOW

**** ORIGINAL ANSWER

(この場合は、しかし、多くの類似のシナリオではないではない仕事、私は警告および/または感激の例として、それを残しておきますので。)

。 。 。他に何も機能していない場合、私はUIWindowをサブクラス化し、代わりに通常のUIWindowのことをアプリデリゲートのインスタンス化を確認していることをお勧めします。あなたは(あなたは、ウィンドウのサブクラスにIVARにMPMoviePlayerへのポインタを保存した場合)、そのクラスにタッチをインターセプトし、通知を送信したり、直接映画をキャンセルすることができます。

@interface MyWindow : UIWindow {
}
@end

@implementation MyWindow
// All touch events get passed through this method
-(UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event
{
   // The screen has been touched, send a notification or stop the movie
   return [super hitTest:point withEvent:event];
}
@end
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top