, iOS7 iOS8.
YouTube, :
#import <MediaPlayer/MediaPlayer.h>
"supportedInterfaceOrientationsForWindow" :
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window{
if ([[window.rootViewController presentedViewController]
isKindOfClass:[MPMoviePlayerViewController class]] || [[window.rootViewController presentedViewController] isKindOfClass:NSClassFromString(@"MPInlineVideoFullscreenViewController")] || [[window.rootViewController presentedViewController] isKindOfClass:NSClassFromString(@"AVFullScreenViewController")]) {
return UIInterfaceOrientationMaskAllButUpsideDown;
}else {
if ([[window.rootViewController presentedViewController]
isKindOfClass:[UINavigationController class]]) {
UINavigationController *nc = (UINavigationController *)[window.rootViewController presentedViewController];
if ([nc.topViewController isKindOfClass:[MPMoviePlayerViewController class]]) {
return UIInterfaceOrientationMaskAllButUpsideDown;
} else if ([[nc.topViewController presentedViewController]
isKindOfClass:[MPMoviePlayerViewController class]]) {
return UIInterfaceOrientationMaskAllButUpsideDown;
}
}
}
return UIInterfaceOrientationMaskPortrait;
}
- ViewController.m
"ViewController.m" "ViewDidLoad", , :
- (void)viewDidLoad
{
[super viewDidLoad];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(youTubeStarted:) name:@"UIMoviePlayerControllerDidEnterFullscreenNotification" object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(youTubeFinished:) name:@"UIMoviePlayerControllerWillExitFullscreenNotification" object:nil];
[self initVideoWebView];
}
This feature allows you to trigger your WebView with a YouTube URL:
- (void) initVideoWebView {
_videoUrl = [NSURL URLWithString:[NSString stringWithFormat:@"https://www.youtube.com/watch?v=%@", _videoID]];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:_videoUrl];
[_webView loadRequest:requestObj];
}
The last thing to do is to implement the functions below on your ViewControler:
-(BOOL) shouldAutorotate {
return NO; }
-(NSUInteger)supportedInterfaceOrientations{
return UIInterfaceOrientationMaskPortrait; }
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation{
return UIInterfaceOrientationPortrait; }
-(NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskPortrait; }
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
return UIInterfaceOrientationPortrait; }
If that helps, speed up :)
source
share