show specific viewcontroller only in landscape, but support iPad multitasking features - iphone

I´m developing an application for iPad & iPhone.
The App is supporting on iPad all Orientations, because of Multitaskingfeatures.
On iPhone my App is supporting only Portrait.
For one Specific ViewController I want on both devices to support only Landscape.
On the iPhone was using following solution:
I disabled all orientations in .plist and worked with two Navigationcontroller.
One for landscape and one for Portrait.
pushing my VC for Landscape:
LandscapeNavigationController *navController = [[LandscapeNavigationController alloc] init];
[UIApplication sharedApplication].keyWindow.rootViewController = navController;
[navController pushViewController:[Logic sharedInstance].myLandscapeViewController animated:YES];
Code in my NavigationController:
- (NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskLandscape;
}
- (BOOL)shouldAutorotate {
return YES;
}
My Problem is that I cant handle the orientation on iPad in code because I have to enable all Orientations in .plist to support Multitasking.
So the delegatemethods supportedInterfaceOrientations in my Navigationcontroller wont be called.
Has anybody an idea to support multitasking on iPad AND allow one specific ViewController only one supportetInterfaceOrientation?

Related

Force Landscape iOS 6

I am looking to have one view in my app have landscape orientation. I have managed to get the view to stay in landscape when rotated manually, but if the device is already portrait, it stays portrait, regardless of its supported orientation (set using supportedInterfaceOrientations method) . Is there a way to get the view to rotate automatically? I have tried:
[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeRight animated:NO];
but this doesn't work.
Any suggestions would be greatly appreciated!
One way to do this is by overriding preferredInterfaceOrientationForPresentation but in order for that to be called the viewController has to be presented (as in modal) and not pushed as mentioned here:
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
NSLog(#" preferred called");
return UIInterfaceOrientationPortrait;
}
In order to present your viewController in a UINavigationController use:
UINavigationController *presentedNavController = [[UINavigationController alloc] initWithRootViewController:protraitViewController];
[self presentViewController:presentedNavController animated:YES completion:nil];
To make UINavigationController respect your current viewController's orientation preferences use this simple category instead of sub-classing.
Also, this part of Apple's documentation is a good read for understanding iOS orientation handling better.
Define the following in the UIViewController for your landscape-only view:
- (UIInterfaceOrientation) supportedInterfaceOrientations
{ return UIInterfaceOrientationLandscapeLeft; } // or right or both
This should prevent your view from ever appearing in portrait. From iOS documentation:
Declaring a Preferred Presentation Orientation
When a view controller
is presented full-screen to show its content, sometimes the content
appears best when viewed in a particular orientation in mind. If the
content can only be displayed in that orientation, then you simply
return that as the only orientation from your
supportedInterfaceOrientations method.

Cocos 2d 2.0 shouldAutorotate not working?

I'm having some issues. I have a cocos2d game I'm just about done developing. However I've run into a problem where I need to enable portrait orientation in my apps plist for game center sign in to work without throwing a SIGABRT error. So once I enable that from my app's build summary page (Or add it to the info.plist file as a supported orientation) it works fine. But then anytime in my game if you turn the iPhone it will flip to portrait mode if it senses you turned it that way. I've tried messing with the shouldAutorotateToInterfaceOrientation method from my AppDelegate.m and it's not getting called AT ALL, not at any time is it being called. I threw an NSLog statement in the method to be sure if it's being called, and it's not.
So, basically my real issue is. I need my game to STAY in landscape mode BESIDES when the Game Center login screen pops up. How do I do this in a Cocos2d 2.0 game?
I'm am using iOS6
First, make sure that the app supports portrait and landscape orientations in the target summary.
Then you'll need to make a new root view controller that forces you into landscape mode so that your game doesn't start rotating strangely:
#implementation CUSTOM_RootViewController
-(NSUInteger)supportedInterfaceOrientations{
return UIInterfaceOrientationMaskLandscape;
}
- (BOOL)shouldAutorotate {
return YES;
}
#end
Finally, in the AppDelegate.m file, replace the original navigation controller with your new one:
// Create a Navigation Controller with the Director
//navController_ = [[UINavigationController alloc] initWithRootViewController:director_];
navController_ = [[SMD_RootViewController alloc] initWithRootViewController:director_];
navController_.navigationBarHidden = YES;
Now you should be able to overlay a portrait view on top.
Hope this helps!
Use this code in AppDelegate.mm
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_6_0
-(NSUInteger)supportedInterfaceOrientations{
return UIInterfaceOrientationMaskLandscape;
}
- (NSUInteger)application:(UIApplication*)application supportedInterfaceOrientationsForWindow:(UIWindow*)window
{
return UIInterfaceOrientationMaskLandscape;
}
#else
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return UIInterfaceOrientationIsLandscape(interfaceOrientation);
}
#endif
In IOs6 shouldAutorotateToInterfaceOrientation method not worked, so u change in appDelegate .m file [window addSubview:viewcontroller] to [window setRootviewcontroller:viewcontroller] after its works fine.

App doesn't rotate on iPhone Simulator

I'm wanting to test out my app with the iPhone 5 resolution, so I'm using the simulator. My app has Portrait and 2 landscape orientations in Supported Device Orientations, and the viewControllers which allow rotation have shouldAutorotateToInterfaceOrientation set to YES. Yet when I rotate the device in the simulator, it doesn't rotate as it does on the device. Right now i'm just using the standard iPhone 4 simulator.
Edit: This is the code I have for setting my VC.
UIViewController *vc = [[UIViewController alloc] init];
self.navigationController = [[UINavigationController alloc] initWithRootViewController:vc];
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
[self.window makeKeyAndVisible];
[self.window addSubview:self.navigationController.view];
self.loadingWood = [[UIImageView alloc] init];
[vc.view addSubview:self.loadingWood];
And then shortly after:
self.timeline = [[JTimelineViewController alloc] init];
[self.navigationController setViewControllers:[NSArray arrayWithObject:self.timeline]];
This is necessary for visuals when the app starts up.
EDIT 2:
I now have this working. The problem I now face is that despite one of my viewControllers stating this, it still rotates upon any rotation on the iPhone Simulator:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
EDIT 3: My phone is running iOS5. The simulator is running iOS6. This is a possible reason. Removing Landscape Left and Landscape Right as supported orientations means no simulator rotation at all, but my iOS5 iPhone 4 continues to rotate as normal.
Make sure that you're setting the root view controller, as in:
self.window.rootViewController = self.navigationController;
I had to deal with something similar in the past. What's going in is that only the main view controller of the application receives the rotation notifications and delegate calls. There are some exceptions, like the UINavigationController, that passes down those events to their current view controller.
So, for example, if your AppDelegate class loads a view controller and that view controller pushes a second view controller, that second view controller will not receive the rotation notifications.
I recommend you use a UINavigationController to push your UIViewControllers onto the display, since UINavigationController passes down the rotation delegate calls and notifications.
EDIT
In Xcode's preference, under the Download tab, you have the option of downloading previous simulators, iOS 5 and iOS 5.1. Download those and set your target iOS version to 5.0 (or 5.1) and select the correct simulator from the device list. See if you get the same problem as with the iOS 6 simulator. If you get that, than there's definitely a difference between iOS 5 and iOS 6's way of handling UINavs.
Also, using the difference between setViewControllers and pushViewController is that pushViewController adds the view controller as a child of the parent view controller, which makes it respond to the delegate calls, including rotation. Since iOS 5, every UIViewController now has a method called addChildViewController that gives that functionality to the UIViewController class.

UITableViewController won't do UIDeviceOrientationPortraitUpsideDown orientation

i got a problem on my UITableViewController it wont do UIDeviceOrientationPortraitUpsideDown orientation. I already set on shouldAutorotateToInterfaceOrientation function allowing the two portrait orientations.
Here's my code on implementing my UITableViewController
UITableViewController *controller = [[UITableViewController alloc] initWithStyle:UITableViewStyleGrouped];
controller.tableView.delegate = self;
controller.tableView.dataSource = self;
controller.tableView.scrollEnabled = NO;
thanks
The most likely explanation is that your app itself won't support upside-down (the Apple human interface guidelines suggest that iPhone apps should not be rotated upside-down.) You can modify this in your project settings within Xcode.
If that's not it, can you post your code for shouldAutorotateToInterfaceOrientation?

How to show iPhone size views on iPad applications

I have an iPhone application (app1) which has to be integrated as a sub-application on another universal iOS app (app2).
For various reasons I don't want to create an iPad interface for my iPhone app1, I just want that all the views will be shown with iPhone dimensions (at the center of the screen) also when the main app2 is executed on an iPad. On app1 I do not support landscape orientation, only portrait.
Is this somehow possible to realize?
Thank you in advance.
This is the code!
UIPopoverController *popoverController = [[UIPopoverController alloc] initWithContentViewController:yourViewController];
[popoverController setPopoverContentSize:CGSizeMake(320, 480)];
And to show the popoverController in the middle of the iPad screen
UIDevice* thisDevice = [UIDevice currentDevice];
if(thisDevice.userInterfaceIdiom == UIUserInterfaceIdiomPad){
[popOverController presentPopoverFromRect:CGRectMake(380, 450, 1, 1) inView:self.view permittedArrowDirections:0 animated:YES];
}
To maintain always the same size of your UIPopoverController do not forget to set the contentSizeForViewInPopover in each view (do this inside the viewWillAppear:)
- (void)viewWillAppear:(BOOL)animated{
[self setContentSizeForViewInPopover:CGSizeMake(320, 480)];
}
Yes - you can do this. Assuming you have built your original application using UIViewControllers, the iPad has a special kind of class called a UIPopoverController where you can spawn a UIViewController onto the screen of the iPad at a given size.
To embed an iPhone app in a iPad app, set the root UIViewController of your iPhone App to the View Controller in the Popover Controller, set the size of the popover to 320x640 and spawn it by calling the presentPopover function.
I hope this helps!
N