Change the orientation of view in iPhone - iphone

I want to change a view's orientation as and when it is displayed.
For Example:
Whenever the user clicks a button a new view is displayed to the user. Whatever may be the orientation,I want to display this view in Landscape mode.
Any Ideas.....

Add this function the in the new view to change the Orientation to landscape mode.
- (BOOL)shouldAutorotateToInterfaceOrientationUIIn terfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight );
}

Use this function in your class.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationLandscapeRight ||
interfaceOrientation == UIInterfaceOrientationLandscapeLeft);
}

Add this to your view controller
- (BOOL)shouldAutorotateToInterfaceOrientationUIIn terfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight );
}

Related

How to handle UI components when device orientation for iPhone/iPad changes?

I have several components on my UIView like textfields, labels, tables, buttons. I want to handle device orientation changes.
How to make these components arrange at right place automatically? Or do I need to re-frame them?
Please help.
Thanks
- (void) willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
[self adjustViewsForOrientation:toInterfaceOrientation];
}
- (void) adjustViewsForOrientation:(UIInterfaceOrientation)orientation {
if (orientation == UIInterfaceOrientationLandscapeLeft || orientation == UIInterfaceOrientationLandscapeRight) {
// set you subviews,Label button frame here for landscape mode,,
}
else if (orientation == UIInterfaceOrientationPortrait || orientation == UIInterfaceOrientationPortraitUpsideDown) {
// set you subviews,Label button frame here for portrait-mode,
}
}
//Don't forget to add this Delegate Method
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation{
// Return YES for supported orientations
return YES;
}
Hope, this will help you..
You may use Autosizing option for the orientation changes.No need to write even a single line of code.
Try this
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
if(interfaceOrientation == UIInterfaceOrientationPortrait || interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown)
{
// portrait Arrangement
}
else
{
// Landscape Arrangement
}
return (interfaceOrientation == UIInterfaceOrientationLandscapeRight ||
interfaceOrientation == UIInterfaceOrientationPortrait ||
interfaceOrientation == UIInterfaceOrientationLandscapeLeft ||
interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown);
}

Supporting orientations IOS

Hello i want to support portrait, home button up and down in my application how can i do that?
i go to my project settings check those two
and i add the code below
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return UIInterfaceOrientationIsPortrait(interfaceOrientation);
}
I also tried
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait || interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown);
}
but none seems to work
any help
Try this
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation{
if((interfaceOrientation == UIInterfaceOrientationPortrait) || (interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown)){
return YES;
}
return NO;
}
If it still doesn't work, you can try this (just for the sake of testing)
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation{
return YES;
}
if this doesn't work, either you are not messing with the right view controller, or the parent/root view controller has rotation disabled (returning NO in shouldAutoRotate method of the rootVC)

iPad application having landscape mode only, issue

if (interfaceOrientation == UIInterfaceOrientationPortrait) {
return NO;
} else if (interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown) {
return NO;
} else if (interfaceOrientation == UIInterfaceOrientationLandscapeLeft) {
NSLog(#"Landscape left detected!");
return NO;
} else if (interfaceOrientation == UIInterfaceOrientationLandscapeRight) {
NSLog(#"Landscape right detected!");
return YES;
}
I am trying to implement an iPad app having landscape mode only. I set the Supported interface orientations as Landscape right mode in info.plist. WHen the application is started, the view is in Landscape mode itself. But when i added another view, such as Home view, after login, view is not rotated as landscape. It was in portrait mode. In the xib file also, i set it as landscape. I have included the above code in both Login and Home view controller.
But the home view is not rotating after login.
First you dont have to write checks for each and every orientation. You can achieve this by simply using the following code in your viewController's shouldAutorotateToInterfaceOrientation method
return (interfaceOrientation == UIInterfaceOrientationLandscapeRight);
Second can you provide more details on how actually you are adding more views. It will be more helpful to find the problem.
do this in each view controller
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight)
}

Supported orientations not limiting actual orientations

I have an iPad game that I only want to see in landscape view. I have selected the landscape view from the target's summary and have the code
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return YES;
}
in my first viewcontroller which is added to a navController. But the only effect that I can see by changing the target's orientations is not how it can be rotated but rather what direction it is first loaded in. Does anyone have any ideas? Thanks!
Try this:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}

pushViewController: - how to display in portrait only mode, when device is in landscape mode?

I have 2 view controllers, root, and detail. The root view controller supports landscape and portrait orientation, so it has the following code:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return (interfaceOrientation == UIInterfaceOrientationPortrait
|| interfaceOrientation == UIInterfaceOrientationLandscapeLeft
|| interfaceOrientation == UIInterfaceOrientationLandscapeRight
|| interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown);
}
The above code works perfectly for the root view controller.
If the root view controller is being displayed, and the user rotates the device into landscape mode, the view adjusts accordingly. From this point, if push my detail view controller on to the stack, it loads in landscape mode. But, it shouldn't, because I have it configured to only support portrait mode. I'm using the code below in my detail view controller:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
In your second view controller, replace your code with ...
return UIInterfaceOrientationIsPortrait( interfaceOrientation );