2
votes

I am making a application which support only Portrait mode.here iam loading youtube videos in uiwebview. so when i switch to landscape mode video has to play in landscape mode also. But after taping on done of videoplayer. my view controller is changing to landscape mode but it has be in portrait mode only here is my webview code

         web=[[UIWebView alloc]initWithFrame:CGRectMake(2,0, 140, 99)];
          web.backgroundColor=[UIColor redColor];
        [web setDataDetectorTypes: UIDataDetectorTypeNone];

        NSString *embedHTML = @"<iframe title=\"YouTube video player\" width=\"320\" height=\"460\" scrolling=\"no\" src=\"http://www.youtube.com/embed/%@?modestbranding=1&amp;rel=0;autoplay=1;showinfo=0;loop=1;autohide=1\" frameborder=\"0\" allowfullscreen allowTransparency=\"true\"></iframe>";

        NSString *htmlStr = [NSString stringWithFormat:embedHTML, [youtubeId_array objectAtIndex:i]];              
         web.tag=i+100;
        web.scrollView.bounces=NO;
        [web loadHTMLString:htmlStr baseURL:nil];
        [view addSubview:web];

  -(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
{
    return ( toInterfaceOrientation=UIInterfaceOrientationPortrait);
}
2

2 Answers

0
votes

Have you tried to set rootViewController to self when you returning to the app?

In your viewcontroller:

import "AppDelegate.h"
...
- (void)functionRunWhenVideoFinish {
    ...
    self.appDelegate.window.rootViewController = self;
    ...
}
0
votes

Add These Lines in Appdelegate and your Required View Controller

while clicking done button app will move required orientation.

-(BOOL)shouldAutorotate
{
    return NO; 
}

-(NSUInteger)supportedInterfaceOrientations
{
    //LandScapeMode:- UIInterfaceOrientationMaskLandscape;
    //PortraitMode:- 
    return UIInterfaceOrientationMaskPortrait 
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
    //LandScapeMode:- UIInterfaceOrientationLandscapeRight;
   // ProtraitMode:-
   return UIInterfaceOrientationPortrait
}