I'm working on an app using IIViewDeck and I only want one view controller to rotate. It's ios 6 and I was able to work out the shouldRotate cascading to get the one that I need to rotate successfully.
My problem is that if I'm in landscape then switch to another view controller, the app remains in landscape. I need to force it back to protestor but I haven't had any success. I thought the simplest approach would be to do some 'force portait' code in the rotatable view controller's viewWillDisapper but I just don't know how to enforce.
Any suggestions?
Your question is also asked here
In all your VC's say yes to rotation, but use an NSUInterger to set the mode like so:
The answer that questions has is below:
-(BOOL)shouldAutorotate
{
return YES;
}
//keep the below code in all your VC's that you do not want to have the rotation capability
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationPortrait;
}
Related
I am implementing searching within my Metro application. The search works well, results and UI come up as expected with one problem though.
I try to display a ProgressRing before the search and hide it after the search completes, but it never gets displayed.
What am I missing, code snippet below:
protected override void OnSearchActivated(Windows.ApplicationModel.Activation.SearchActivatedEventArgs args)
{
// Some Metro designer generated code here
// Show progress ring
MainPage.Current.ResetProgressRingState(true);
// Bind search results
MainPage.Current.BindSearchResults(args.QueryText);
// Ensure the current window is active
Window.Current.Activate();
// Hide progress ring
MainPage.Current.ResetProgressRingState(false);
}
I suspect that the BindSearchResults method needs to be awaited in order for the ProgressRing to work correctly. If so, what's the easiest way to make that method awaitable, if not please advise what I am missing here.
If so, what's the easiest way to make that method awaitable, if not please advise what I am missing here.
Mark it as async and have it return Task. Within that method, use await on other asynchronous operations.
I'm failrly new to LibGDX and I'm running into a problem.
I'm building a classically styled RPG/Adventure game in which I'm using a TiledMap(-Renderer) to create the map. I've followed different tutorials but can't get it to work. (last one was DPG's: Full working example link)
What I need, is a column of buttons on the right side of the screen (implemented that through ImageButtons). One of these buttons lead to a settings-kind of screen and another one should lead to the game map. Under a ClickListener of the button I've added DPK's code of
MapHelper map = new MapHelper();
map.setPackerDirectory("data/packer");
map.loadMap("data/world/level1/level.tmx");
map.prepareCamera((int)stage.getWidth(), (int)stage.getHeight());
map.getCamera().update();
map.render();
The MapHelper class is an exact copy of dpk's, only change above is the setting of the width and height of the camera. Any suggestion what I'm doing wrong here?
I don't think you want to invoke map.render() in the ClickListener callback. That would mean the map is only rendered when you click, and then not re-rendered (generally everything gets re-rendered on every screen re-fresh).
I think you need to track the map in your application class, and in the ClickListener callback you need to set a flag or somehow "enable" the map (perhaps setting it to something other than null). Then in the application's render() method you can check to see if the map should be rendered or not, and render it if so.
Specifically, move the calls to prepareCamera, getCamera and render out of the ClickListener.
In iOS 5, my application I used the method to change my orientation:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return (interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}
In iOS 6 I think I'm supposed to do this, but it does nothing! My app is rotated not the way I want it to be.
- (BOOL) shouldAutorotate
{
return YES;
}
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskLandscapeRight;
}
It's how I was adding my viewController.
I replaced this line code:
[window addSubview:viewController.view];
by this line:
[window setRootViewController:viewController];
When the device changes orientation, in iOS 6, the system asks the application which orientation it supports. The application will return a number of orientations it accepts.
How does the application determine it's orientation?
First the application checks it's info.plist orientations (this is very important to determine which orientation to use for launch.
Secondly it asks it's application delegate for it's orientations, this can be specified via the -(NSUInteger)application:supportedInterfaceOrientationsForWindow: method. This effectively overrides the info.plist setting, this implementation is optional. By default iPad apps orientate in all directions and iPhone in all but upside down.
Lastly the application delegate queries it's top most view controller, this can be a UINavigationController or a UIViewController... etc, then it specifies how to be presented and if it wants to autorotate. These UIViewControllers can use shouldAutorotate: and supportedInterfaceOrientations methods to tell the app delegate how to present it.
You must make sure you set the root view controller of your window.
Also if you are presenting any other view controllers in full screen such as a modal view controller, this is the one responsible for determining orientation changes or not.
For me the solution worked, the case was different a bit, because I had a UINavigationController.
My case was that I needed all Portrait window except one. I had to enable all landscape and the portrait orientations in targets (otherwise it crashes on the only landscape view).
So in this case:
create a subclass for UINavigationController,
insert the rotationspecific stuff there
and use the subclass instead of UINavigationController.
If you are using a UINavigationController, it sends the supportedInterfaceOrientations: message to the UINavigationController itself rather than the top most view controller (i.e. what you would actually want it to do).
Instead of having to subclass UINavigationController to fix it, you can simply add a category to UINavigationController.
I created a new variable in my singleton: canRotate, and I set it to YES when I want the viewcontroller to support some orientation.
In appDelegate I added this:
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
if([[SharedData sharedInstance] canRotate])
{
return (UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight);
}
return UIInterfaceOrientationMaskPortrait;
}
in my case it works. I have a custom tabbar and UINavigationviewControllers are added as subviews to rootViewController.
I know this sounds pretty elementary, but I was wracking my brain to figure out orientation issues while testing on my iPhone - I had the physical auto lock mode in Portrait mode - so nothing I changed programmatically mattered - thought this should be troubleshooting step number 1!
I have a uiNavigationController and two viewControllers. The problem I am having is the views are being generated in portrait size even though I want them in landscape!
Here is what I am doing:
1) Creating an instance of view1 and adding it to the uiNavigationControllers stack. This is performed inside the applications delegate didFinishLoadingWithOptions(...) method.
2) view1 has a button that when clicked creates an instance of view2 and pushes it onto the uiNavigationControllers stack.
This appears to work fine apart from the fact the views are being created in portrait format. I was going to manually force landscape by using transform methods once I create their instance but this feels really hacky.
I did speculate that this has something to do with the "shouldAutorotateToInterfaceOrientation" method, but this is set for landscape in all viewControllers.
I am royally confused.
Question 1) How on earth do I solve this, is the 'hacky transform' approach the only way?
Question 2) Is this the correct way to be using a navigationController - I am new to iPhone programming. All I want are two landscape views that I can click between and this seems to do this aside from the landscape bit ^^.
I found the answer for this problem.
The navigation controller DOES inherit the shouldAuthororateToInterfaceOrierntation method for each of the views inside its stack, I however made a mistake :)
After adding the navController to the main window I had not deleted the part where by default it adds the a rootController view to the main window. There was some kind of conflict which stopped my navigation controller working as expecting - removing that line fixed everything.
Whenever my app is rotated, only the viewController of which I've added his view as a subview to the mainwindow gets his interfaceOrientation property updated, the rest remains ignorant of the fact the device has been rotated.
Is it my responsibilty to notify other objects of the change, and if so, what's a nice way to do it?
I've looked into setting interfaceOrientation of my children-viewcontrollers but that's readonly.
Thanks in advance,
I found that calling
willRotateToInterfaceOrientation
and/or
didRotateFromInterfaceOrientation
of the view controller you are going to show worked for me. In my case I was using a Navigation Controller so it was easy to keep track of what was going to be shown to the user next. Below is some code from my project.
- (void)navigationController:(UINavigationController *)navigationController
didShowViewController:(UIViewController *)viewController
animated:(BOOL)animated {
[viewController willRotateToInterfaceOrientation:
[self interfaceOrientation] duration:0];
}