iPhone interface orientation change not returning to portrait orientation - iphone

So I have a view that I present modally when the interface orientation changes to landscape. However when the orientation returns to portrait and the modal view dismisses itself, the tableview from the initial view remains in landscape orientation (this table view must be only in portrait orientation)
Here is the code :
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return ((interfaceOrientation == UIInterfaceOrientationPortrait) || (interfaceOrientation == UIInterfaceOrientationLandscapeLeft) || (interfaceOrientation == UIInterfaceOrientationLandscapeRight) );
}
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
if ((toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft) || (toInterfaceOrientation == UIInterfaceOrientationLandscapeRight)) {
[self performSegueWithIdentifier:#"showCatChart" sender:self];
}
if (toInterfaceOrientation == UIInterfaceOrientationPortrait) {
[self refreshTableView];
}
}
I tried to refresh the tableview but that doesn't make it portrait again ...
this could be from the view hierachy ...
NavigationController->tableView (only portrait)->tableview->landscapeViewModalController

With iOS 6, you need to implement the following:
- (BOOL)shouldAutoRotate {
return YES;
}
- (NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskAll;
}
In your AppDelegate, you need to change the following:
[self.window addSubview:viewController.view];
to
[self.window setRootViewController:viewController];
Also, keep your current code if you want to support previous versions of iOS.

Use the following in appdelegate.
[self.window addsubview:viewcontroller];
This alone will solve your orientation problem.

Related

Supported orientation madness

I know this is the most commonly asked question and trust me I have tried every kind of combination to make this happen and went through most posts here on stack overflow.
I have a UINavigationController called v1ViewController and what I am trying to do is when it is shown to the user I just want it to either show in portrait or portrait-up-side-down modes, no landscape even if the user rotates the device in landscape it shouldn't do anything.
NOTE: I did highlight all options in Xcode for supported interface orientations as in one of my other view controller I need to show user something in both landscape and portrait modes but for this UINav Conrtoller I want it to just remain in portrait modes.
The code I have for iOS 5.0 work just fine without a problem.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
if (interfaceOrientation == UIInterfaceOrientationPortrait)
{
return YES;
}
else if (interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown)
{
return YES;
}
else
{
return NO;
}
}
the headache I have is with iOS 6. No matter what I try and do it still lets the user rotate the bloody thing in landscape (see code and screenshots)
// *********************
// iPhone 5 orientation support
// *********************
- (BOOL)shouldAutorotate
{
UIInterfaceOrientation interfaceOrientation = [[UIDevice currentDevice] orientation];
if (interfaceOrientation == UIInterfaceOrientationPortrait)
{
return YES;
}
else if (interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown)
{
return YES;
}
else
{
return NO;
}
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return UIInterfaceOrientationPortrait;
}
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskPortraitUpsideDown;
}
You need to ensure you override the base UINavigationController and assign a custom class to it(not just the viewController that is the subview for the UINavController..ie the view contained below the navigationBar). Inside the UINavigationController, return NO on shouldAutoRotate.

Issue on UIOrientation in ipad

I'm developing the app for all the orientations in Ipad....But during the development I did only for landscape mode..But nw I want to change to all the possible orientations... Here I got some problem....
Here is the code...
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
//return YES;
return (interfaceOrientation == UIInterfaceOrientationLandscapeRight || UIInterfaceOrientationPortrait);
}
- (void) willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
[self adjustViewsForOrientation:toInterfaceOrientation];
}
- (void) adjustViewsForOrientation:(UIInterfaceOrientation)orientation {
if (orientation == UIInterfaceOrientationLandscapeLeft || orientation == UIInterfaceOrientationLandscapeRight)
{
\\Here I did my stuff..
}
else if (orientation == UIInterfaceOrientationPortrait || orientation == UIInterfaceOrientationPortraitUpsideDown)
{
\\Here I did my stuff..
}
}
The problem is,When the simulator is launched and if itz in the landscape mode,I got the proper size of the views,but if the simulator is in potrait mode I can't get what I want... If I change the orientations of simulator I get the correct size of the views...
This was the same problem that was facing.
And i solved it by doing this:
First change this function:
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return YES;
}
and then in the viewDidLoad function you can check whether the device is in landscape or in Portrait.
-(void)viewDidLoad
{
if (UIInterfaceOrientationIsLandscape(self.interfaceOrientation))
{
//landscape view code
}
else
{
//portrait view code
}
}
hope this will help

present modal view on rotate

So I have a UITableViewControler displaying a tableview in portrait mode.
As soon as i rotate the iPhone i want to present a modal view in landscape mode.
In the tableView i use:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}
And to handle the present the modal view:
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation duration:(NSTimeInterval)duration {
if((interfaceOrientation == UIInterfaceOrientationLandscapeRight) || (interfaceOrientation == UIInterfaceOrientationLandscapeLeft))
{
NSLog(#"Push page view");
PagingViewController *s = [[PagingViewController alloc] initWithNibName:#"PagingView" bundle:nil];
s.hidesBottomBarWhenPushed = YES;
[self presentModalViewController:s animated:YES];
[s release];
}
}
The modal view i have the following:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}
And to dismiss the modal view it self, I do:
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation duration:(NSTimeInterval)duration {
if (interfaceOrientation == UIInterfaceOrientationPortrait)
{
NSLog(#"Dismiss my self");
[self.parentViewController dismissModalViewControllerAnimated:YES];
}
}
Some how this works two times.
The third time i rotate the iPhone from Portrait mode to Landscape mode, i get a bad access error.
I cant figure out what gives me the error.
Anyone care for a shot?
The simplest way I can think of is to implement -shouldAutorotate... and dismiss the modal view and return NO to abort rotation. Perhaps that will be sufficient to avoid any concurrency issues. If this suggestion isn't to your liking take a look at NSNotificationCenter.

How do I display a landscape coverflow style view when device is rotated?

I'm working on an app that will need to display a coverflow style view in landscape when the device is rotated to landscape orientation. I've worked on a few apps before, but none of them required landscape/rotation so I'm not experienced with it. I have the code to draw the coverflow view, but presenting it is proving tough.
What I'd like is basically like what the iPod app does when displaying coverflow. The view underneath does not rotate, but the coverflow fades in on top, and fades out when rotated back to portrait.
I'm guessing it's something to do with shouldAutorotateToInterfaceOrientation and a modal view being presented with a fade transition, or using the technique found here:
http://www.iphonedevsdk.com/forum/iphone-sdk-development/22285-replicating-cool-ipod-landscape-transition-iphone.html
I guess my main problem is that the modal view is presented, but it's contents are not rotated to landscape. What should I do?
Here's the code I'm using now:
PARENT VIEW
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation{
NSLog(#"rotating?");
if (interfaceOrientation == UIInterfaceOrientationPortrait) {
return YES;
}
if ((interfaceOrientation == UIInterfaceOrientationLandscapeLeft) || (interfaceOrientation == UIInterfaceOrientationLandscapeRight)) {
NSLog(#"rotating");
CoverFlowViewController *coverFlowView = [[CoverFlowViewController alloc] init];
[coverFlowView setModalTransitionStyle:UIModalTransitionStyleCrossDissolve];
[self presentModalViewController:coverFlowView animated:YES];
[coverFlowView release];
}
return YES;
}
MODAL VIEW
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
NSLog(#"rotating? going back?");
if ((interfaceOrientation == UIInterfaceOrientationLandscapeLeft) || (interfaceOrientation == UIInterfaceOrientationLandscapeRight)) {
return YES;
} else {
[self.parentViewController dismissModalViewControllerAnimated:YES];
}
return NO;
}
You should do the transition inside:
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
}

Load mainView with shouldAutorotateToInterfaceOrientation

I am trying to load a view with the shouldAutorotateToInterfaceOrientation method, but I have a problem. When the device runs as landscape, I want to show the main view itself, and when when the device is portrait, load a custom UIView.
Here is my code:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
if ((interfaceOrientation == UIInterfaceOrientationLandscapeLeft)|| (interfaceOrientation == UIInterfaceOrientationLandscapeRight))
//doesn't show main view !!
self.view;
else if ((interfaceOrientation == UIInterfaceOrientationPortrait) || (interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown))
//works fine !
self.view = portraitView;
return YES;
}
I figured out !!!! just call the view with modal on a method
- (void) mainView {
screenTestViewController *mv = [[screenTestViewController alloc]initWithNibName:#"screenTestViewController" bundle:nil];
[self presentModalViewController:mv animated:NO];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
if ((interfaceOrientation == UIInterfaceOrientationLandscapeLeft)|| (interfaceOrientation == UIInterfaceOrientationLandscapeRight))
[self mainView];
.
.
.
You should push your custom UIView in: willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation duration:(NSTimeInterval)duration