1. Welcome to the new MacRumors forums. See our announcement and read our FAQ

Orientation issue....

Discussion in 'iPhone/iPad Programming' started by primedime, Apr 13, 2011.

  1. macrumors member

    #1
    Ok, I have a view that basically is a UIWebView that pulls up the mobile youtube site. Everything works perfectly but when I play the videos they only show in Portrait and don't allow me to turn it sideways to get a Landscape look so that the video takes up the screen.

    Now I have tried all of the orientation codes but when I apply them it causes my application to hang at the splash screen... is there something else I should be setting besides just adding this code? Also, the youtube view of my app is not the first view that shows when the app launches.

    Code:
    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    
        // Return YES for supported orientations
    
        return YES;
    
    }
    I looked in IB and didn't really see anything that gives the view authority to switch orientation. I only see the option to make it Portrait or Landscape.
     
  2. macrumors member

    #2
    Check if this works...

    Code:
    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    	
    	return (interfaceOrientation == UIInterfaceOrientationLandscapeRight);
    }
     
  3. macrumors member

    #3
    Nope, didn't work either. I have a tab bar and toolbar on this view, does that have any effect on this working or not?

    Here is the full code for the view:

    Code:
    #import "YoutubeViewController.h"
    @implementation YoutubeViewController
    @synthesize myWebView;
    @synthesize spinnerView;
    @synthesize toolbar;
    
    - (void)loadWebPageWithString:(NSString *)urlString
    {
    	NSURL *url = [NSURL URLWithString:urlString];
    	NSURLRequest *request = [NSURLRequest requestWithURL:url];
    	[myWebView loadRequest:request];
    }
    
    -(IBAction)stopLoading
    {
    	NSLog(@"stopLoading");
    }
    -(IBAction)goHome 
    {
        NSString *urlAddress = @"http://www.m.youtube.com/saleshuddle";
        
        NSURL *address = [NSURL URLWithString:urlAddress];
        NSURLRequest *requestObj = [NSURLRequest requestWithURL:address];
        [myWebView loadRequest:requestObj];
    }
    -(IBAction)reload
    {
    	NSLog(@"reload");
    }
    
    - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
    {
        self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
        if (self) {
            // Custom initialization
        }
        return self;
    }
    
    - (void)viewWillDisappear:(BOOL)animated
    {
    	[myWebView stopLoading];
    }
    
    - (void)dealloc
    {
        [myWebView release];
    	[spinnerView release];
        [super dealloc];
    }
    
    - (void)didReceiveMemoryWarning
    {
        // Releases the view if it doesn't have a superview.
        [super didReceiveMemoryWarning];
        
        // Release any cached data, images, etc that aren't in use.
    }
    
    #pragma mark - View lifecycle
    
    - (void)viewDidLoad
    {
        [super viewDidLoad];
    	
    	[self.myWebView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.m.youtube.com/saleshuddle"]]];
    }
    
    - (void)viewDidUnload
    {
        [super viewDidUnload];
        // Release any retained subviews of the main view.
        // e.g. self.myOutlet = nil;
    }
    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    	
    	return (interfaceOrientation == UIInterfaceOrientationLandscapeRight);
    }
    
    #pragma mark -
    #pragma mark UIWebViewDelegate methods
    
    - (void)webViewDidStartLoad:(UIWebView *)myWebView
    {
    	[spinnerView startAnimating];
    }
    
    - (void)webViewDidFinishLoad:(UIWebView *)myWebView
    {
    	[spinnerView stopAnimating];
    }
    @end
    
     
  4. macrumors member

    #4
    sorry I forgot to mention one more thing as well.. you got to do one change in the plist file..

    In the plist file, add a new row at the end and in the "information Property list" type in "Initial Interface Orientation" and in the "value" type in "Landscape(right home button)"

    Those are the changes I did...
    and no having a tab bar and a toolbar should not affect it as far as I know but I may be wrong...

     
  5. macrumors member

    #5
    No, that didn't work either. Also, I don't need my initial view to be able to change orientation i just need one of my subviews to be able to, specifically my view that has a UIWebView showing the mobile youtube page.
     

Share This Page