Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

sujithkrishnan

macrumors 6502
Original poster
May 9, 2008
265
0
Bangalore
Hi,

I am trying to detect the interface orientation in my only viewcontrollers' loadView method. I tried with device orientation, status bar orientation and view controller orientation, where all gives the default (portrait) values.

I want to show image-A if the startup-orientation is L/S and image-B if portrait.

Please help!
 
Hi,

I am trying to detect the interface orientation in my only viewcontrollers' loadView method. I tried with device orientation, status bar orientation and view controller orientation, where all gives the default (portrait) values.

I want to show image-A if the startup-orientation is L/S and image-B if portrait.

Please help!

You should ask in the Programming forum. Regardless, have you looked into the Default-Portrait and Default-Landscape files?

http://developer.apple.com/iphone/library/qa/qa2010/qa1588.html

Also,

In your Info.plist file:

Specify values for the UISupportedInterfaceOrientations key for the supported orientations.
Specify values for the UIInterfaceOrientation key for the initial launch orientation.
 
You should ask in the Programming forum. Regardless, have you looked into the Default-Portrait and Default-Landscape files?

http://developer.apple.com/iphone/library/qa/qa2010/qa1588.html

Also,

In your Info.plist file:

Specify values for the UISupportedInterfaceOrientations key for the supported orientations.
Specify values for the UIInterfaceOrientation key for the initial launch orientation.


I know about the Default-<parameter>.png images. And the device is picking the image based on orientation. I want t get the orientation in my loadView method, where i want to show another image after Default image, but the new image is different for different orientation, All the orientation methods are giving me Portrait/Unknown as return value. :(
 
The orientation will always be portrait when loadView is called. That's fine. Just load up your portrait appearance. Then properly adjust your appearance for rotation.
 
I was looking at this a bit this morning. From what I can tell by default it seems to load portrait first and then rotate the view. There may be a better way of doing this but this is what I figure should work.

Code:
- (void)viewDidLoad {
    [super viewDidLoad];
	portraitBackground = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:@"back-portrait.png"]];
	landscapeBackground = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:@"back.png"]];
	self.view.backgroundColor = portraitBackground;
}


Code:
- (void) willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
	self.view.backgroundColor = nil;
	if ((toInterfaceOrientation == UIInterfaceOrientationPortrait) || (toInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown)) {
		self.view.backgroundColor = portraitBackground;
	}
	else {
		self.view.backgroundColor = landscapeBackground;
	}
}
 
I was looking at this a bit this morning. From what I can tell by default it seems to load portrait first and then rotate the view. There may be a better way of doing this but this is what I figure should work.

Code:
- (void)viewDidLoad {
    [super viewDidLoad];
	portraitBackground = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:@"back-portrait.png"]];
	landscapeBackground = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:@"back.png"]];
	self.view.backgroundColor = portraitBackground;
}


Code:
- (void) willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
	self.view.backgroundColor = nil;
	if ((toInterfaceOrientation == UIInterfaceOrientationPortrait) || (toInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown)) {
		self.view.backgroundColor = portraitBackground;
	}
	else {
		self.view.backgroundColor = landscapeBackground;
	}
}



Sounds good, i wil try .

Thanks a million
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.