PDA

View Full Version : Orientation issue....




primedime
Apr 13, 2011, 09:01 AM
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.

- (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.



ashwinr87
Apr 13, 2011, 12:41 PM
Check if this works...

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {

return (interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}

primedime
Apr 13, 2011, 12:46 PM
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:

#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

ashwinr87
Apr 13, 2011, 12:50 PM
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...

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:

#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

primedime
Apr 13, 2011, 02:16 PM
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.