2

私はiPhoneを初めて使用し、webViewでビデオを再生しようとしています。そのため、完了ボタンアクションが必要です。助けてください。

4

2 に答える 2

0

ビデオがUIWebViewで再生されている場合は、ビデオが再生されたとき、およびWebビューでURLをロードするために使用したコードとともに次のコードを使用して[完了]ボタンが押されたときにアクセスできます。

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(videoPlayStarted:) name:@"UIMoviePlayerControllerDidEnterFullscreenNotification" object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(videoPlayFinished:) name:@"UIMoviePlayerControllerDidExitFullscreenNotification" object:nil];

そしてそれはからアクセスすることができます

BOOL isVideoInFullScreenMode;//Temperory added here.. must be in .h file or at teh top if required
-(void)videoPlayStarted:(NSNotification *)notification{
//Your stuff here
   isVideoInFullScreenMode = YES;
}

-(void)videoPlayFinished:(NSNotification *)notification{
    //Your stuffs here
    isVideoInFullScreenMode = NO;
}
于 2012-10-03T12:49:37.103 に答える
0

最後に、完了ボタンアクションの解決策を見つけました...このロジックは、iPadとiPhoneの両方でも機能します..UIGestureRecognizerを使用してこの問題を解決しました。

これが私のコードです。

まず、使用して EnterFullScreen の通知を追加しています

 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(youTubeStarted:) name:@"UIMoviePlayerControllerDidEnterFullscreenNotification" object:nil];

今、youTubeStartedメソッドにこのコードを追加しました..

-(void)youTubeStarted:(NSNotification *)notification{
if (!tapRecognizer1) {
    tapRecognizer1 = [[UITapGestureRecognizer alloc] init];
    tapRecognizer1.delegate = self;
    [tapRecognizer1 setNumberOfTapsRequired:1];
    [self.view addGestureRecognizer:tapRecognizer1];
}    
}

これにより、ムービープレーヤーに TapRecognizer が追加されます。

そして、次のデリゲートメソッドは、ボタンが完了したかどうかを確認します

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch{
NSLog(@"%@",touch.description);
NSString *ViewName = touch.description ;
CGPoint location = [touch locationInView:touch.view];
NSLog(@"location x===%f , location y=== %f",location.x,location.y);
NSRange Check = [ViewName rangeOfString:@"UINavigationButton"];
NSRange checkFrameOfButton;
if (UI_USER_INTERFACE_IDIOM()==UIUserInterfaceIdiomPad) {
   checkFrameOfButton = [ViewName rangeOfString:@"frame = (7 7; 50 30)"];
    if (checkFrameOfButton.length <= 0) {
        checkFrameOfButton = [ViewName rangeOfString:@"frame = (7 7; 51 30)"];
    } 
}
else {
    checkFrameOfButton = [ViewName rangeOfString:@"frame = (5 7; 48 30)"];
    if (Check.length<=0) {
        Check = [ViewName rangeOfString:@"UIView"];
    }
}
if (location.y<40 && location.x<85 && Check.length>0 && checkFrameOfButton.length>0) {
    [self endplaying];  
    }
    return YES;
}

エンドプレイ方法では、やりたいことができます...

于 2012-10-06T06:29:17.657 に答える