我是 Iphone 新手,正在尝试在 webView 中播放视频。所以,我需要完成按钮操作。请帮帮我。
问问题
1145 次
2 回答
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;
}
现在在 endplaying 方法中,你可以做你想做的事......
于 2012-10-06T06:29:17.657 回答
0
如果视频在 UIWebView 中播放,那么您可以使用以下代码以及在 webview 中加载 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 回答