大佬教程收集整理的这篇文章主要介绍了全屏播放YouTube视频,仅允许针对iOS7和iOS8的视频进行旋转,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
// Create the URL _videoUrl = [NSURL URLWithString:[NSString StringWithFormat:@"https://www.youtube.com/watch?v=%@",_videoID]]; // Create the request with the URL NSURLrequest *requestObj = [NSURLrequest requestWithURL:_videoUrl]; // Load the request into the Web View [_webView loadrequest:requestObj];
youtube页面显示,当我对视频开始播放时,但它没有旋转.
我花了一周时间寻找不同的解决方案,通过实现“shouldAutorotate”和“supportedInterfaceOrientations”,但没有成功!
我尝试的最后一件事是在视频以全屏模式播放时添加一个监听器,在AppDelegate.m中我添加了“didFinishLaunchingWithOptions”代码如下:
[[NsnotificationCenter defaultCenter] addObserver:self SELEctor:@SELEctor(moviePlayerWillEnterFullscreenNotification:) name:MPMoviePlayerWillEnterFullscreenNotification object:nil]; [[NsnotificationCenter defaultCenter] addObserver:self SELEctor:@SELEctor(moviePlayerWillExitFullscreenNotification:) name:MPMoviePlayerWillExitFullscreenNotification object:nil];
并实施:
- (void) moviePlayerWillEnterFullscreenNotification:(Nsnotification*)notification { self.allowRotation = YES; } - (void) moviePlayerWillExitFullscreenNotification:(Nsnotification*)notification { self.allowRotation = NO; } -(NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window { if (self.forceLandscapeRight) { return UIInterfaceOrientationMaskLandscapeRight; } if (self.allowRotation) { return UIInterfaceOrientationMaskPorTrait | UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight; } return UIInterfaceOrientationMaskPorTrait; }
问题是既没有调用“moviePlayerWillEnterFullscreenNotification”或“moviePlayerWillExitFullscreenNotification”.
请帮忙!
我不得不使用
[[NsnotificationCenter defaultCenter] addObserver:self SELEctor:@SELEctor(youTubeStarted:) name:@"UIMoviePlayerControllerDidEnterFullscreenNotification" object:nil]; [[NsnotificationCenter defaultCenter] addObserver:self SELEctor:@SELEctor(youTubeFinished:) name:@"UIMoviePlayerControllerWillExitFullscreenNotification" object:nil];
代替
[[NsnotificationCenter defaultCenter] addObserver:self SELEctor:@SELEctor(moviePlayerWillEnterFullscreenNotification:) name:MPMoviePlayerWillEnterFullscreenNotification object:nil]; [[NsnotificationCenter defaultCenter] addObserver:self SELEctor:@SELEctor(moviePlayerWillExitFullscreenNotification:) name:MPMoviePlayerWillExitFullscreenNotification object:nil];
并在我的ViewControler中实现方法
-(BOOL) shouldAutorotate { return NO; } -(NSUInteger)supportedInterfaceOrientations{ return UIInterfaceOrientationMaskPorTrait; } - (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation{ return UIInterfaceOrientationPorTrait; }
有关详细信息:iOS 6.0+ autorotation for youtube embedded video
希望这会有所帮助:)
以上是大佬教程为你收集整理的全屏播放YouTube视频,仅允许针对iOS7和iOS8的视频进行旋转全部内容,希望文章能够帮你解决全屏播放YouTube视频,仅允许针对iOS7和iOS8的视频进行旋转所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。