編集: ムービーはアプリのメイン ウィンドウの上に重ねられた 2 番目のウィンドウに表示されるため、最初のソリューションは機能しません (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];
}
注意: ムービー プレーヤーへの参照をインスタンス変数に保存する必要があります。アクセスに使用できるプロパティを宣言するのが最も便利です。そのため、例self.intro
の代わりに使用intro
されます。インスタンス変数とプロパティを宣言する方法がわからない場合は、このサイトや他の場所にたくさんの情報があります。
**** 以下の元の回答
(この場合は機能しませんが、多くの同様のシナリオでは機能しないため、警告および/または刺激的な例として残します。)
. . . 他に何も機能しない場合は、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