I'm using GPUImage which has class for a preview image. The preview image has to be set to the screen orientation for it to output correctly. Therefore, I need to get the correct orientation on app launch. However, testing [UIDevice currentDevice].orientation in viewDidLoad or viewWillAppear always returns 0 (Unknown).
So I force the orientation like so in viewDidLoad:
NSNumber *value = [NSNumber numberWithInt:UIInterfaceOrientationPortrait];
[[UIDevice currentDevice] setValue:value forKey:#"orientation"];
and it works on the iPhone and iPad mini - when app is launched in landscape, the device detects that it isn't in Portrait and reorients itself to landscape. This then calls viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator
and the correct output is set for GPUImage's preview.
However, in the larger iPad sizes, this does not occur. When the app is launched in Landscape, it thinks it's in Portrait and does not redraw to Landscape as it does in the iPad Mini or iPhone. No call is made to viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator. I know it's because iPad in Portrait or Landscape is considered the same orientation. Somehow I need the app to know it's in Landscape after it launches so it can call the rotation methods.
Any advice?
Related
I am trying to integrate Game Center into my game.
So I receive the the viewcontroller from the game center and I present it.
My game is only landscape but when i launch the game the Game Center login is in portrait.
My game's viewcontroller has supportedOrientations and preferredOrientation return only landscape and shouldAutorotate is set to Yes; Info plist countains also only landscape.
When I print in the xCode console the prefered orientation for the viewcontroller i receive from the gamecenter, it says portrait.
This happens only at launch and only on iOS 8: game is landscape, gamecenter is portrait, dispite the fact that infoplist and game viewcontroller's orientation is only landscape.
I want my GameCenter to be also landscape and I've trying using:
**
NSNumber *value = [NSNumber numberWithInt:UIInterfaceOrientationLandscapeLeft];
[[UIDevice currentDevice] setValue:value forKey:#"orientation"];
**
and it works but it will get rejected by Apple since it forces the orientation.
I've also tryed using modalPresentationStyle setted to UIModalPresentationCurrentContext but it didn't work.
Any more ideas ? please, I'm desperate :P
In my case, this is how I solved this problem:
gcLoginViewController.modalPresentationStyle = UIModalPresentationOverCurrentContext;
gcLoginViewController is the UIViewController you receive in the localPlayer's authenticateHandler.
I also made sure that supportedInterfaceOrientationsForWindow in the app's delegate returns only landscape.
It worked fine with ios 8.1.1 & 8.1.2 on 2 different devices.
I have 2 root view controllers ViewController1 and TabBarController1(there are reasons for making 2 root view-controllers). ViewController1 only supports Portrait mode and TabBarController1 supports all orientations. ViewController1 appears first after launch. I am locking the orientation of ViewController1 using the following method.
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait;
}
The app launch and orientation worked fine with iOS7.
When building the app through Xcode 6 in iPad(iOS8) following change is observed:
- When app is launched in landscape mode, ViewController1 with orientation locked into portrait mode appears with half black screen and when TabBarController1 appears which supports all orientations, doesn't resize with proper dimensions on changing orientations.
I have also tried overriding the above method in TabBarController1 to support all orientation but nothing works fine.
This problem is not observed when launching the app on iPad in portrait mode.
There is no problem when launching the app on iPhone as iPhone launches only in Portrait mode.
What is the issue when working with iOS8 ?
I am a newbie, so don't judge..
In ios8, apple changed 2 things :
1-
[[UIscreen mainscreen] bounds].size
This used to be a fixed value for portrait and landscape, now it is not.
When u change from landscape to portrait the width and height switch.
2-What is happening with you. You cannot force a viewcontroller to be in portrait only if you set portrait and landscape in project settings, do not know why, so you maybe have to set portrait only in project settings for example..
This is happening on iPads and iphone 6+ only.
Hope this helped..
What's the Difference between Interface Orientation and Device Orientation?
Both of them seems the same but what's the actual difference between them?
Interface Orientation can be anything, regardless of device orientation. Device Orientation is the actual physical orientation of the device you are holding, and this is not variable; it is what it is. If you are holding in Portrait, it is Portrait. But just because the device is in Portrait doesn't mean your interface is also in portrait. You may require your app to only provide landscape orientation, hence the interface orientation would be different than the device orientation.
Following description got from this site.
UIDeviceOrientation is a property of the UIDevice class, and there are these possible values:
UIDeviceOrientationUnknown - Can't be determined
UIDeviceOrientationPortrait - Home button facing down
UIDeviceOrientationPortraitUpsideDown - Home button facing up
UIDeviceOrientationLandscapeLeft - Home button facing right
UIDeviceOrientationLandscapeRight - Home button facing left
UIDeviceOrientationFaceUp - Device is flat, with screen facing up
UIDeviceOrientationFaceDown - Device is flat, with screen facing down
As for UIInterfaceOrientation, it is a property of UIApplication and only contains 4 possibilities which correspond to the orientation of the status bar:
UIInterfaceOrientationPortrait = UIDeviceOrientationPortrait
UIInterfaceOrientationPortraitUpsideDown = UIDeviceOrientationPortraitUpsideDown
UIInterfaceOrientationLandscapeLeft = UIDeviceOrientationLandscapeRight
UIInterfaceOrientationLandscapeRight = UIDeviceOrientationLandscapeLeft
(copied from docs)
For example, the device (the actual iPhone or iPod) could be in UIDeviceOrientationLandscapeRight but if your app doesn't support that, it (your app) might still be in UIInterfaceOrientationPortrait.
In addition, to get UIDeviceOrientation, you use [[UIDevice currentDevice] orientation], and to get UIInterfaceOrientation, you use [[UIApplication sharedApplication] statusBarOrientation]
More info
How does one detect the correct orientation of the application on the first view? I need to know so I can either display a portrait image or landscape image as the background.
[[UIDevice currentDevice] orientation] doesn't work properly if the iPad is laid down flat on a surface.
statusBarOrientation doesn't seem to return the correct results for the very first view that is loaded. I tried getting the status bar orientation in the viewWillAppear and viewDidLoad and both returned Portrait even when in landscape.
I have confirmed that I have [self.window makeKeyAndVisible] in my AppDelegate.m in - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions. This is only returning the incorrect status bar orientation on the first view controller.
Note: I have also tried the interfaceOrientation from the UIViewController, ad that still returns portrait no matter what.
Any ideas how to fix this?
EDIT:
I am using the [[UIDevice currentDevice] orientation] to detect if it is portrait or landscape but my issue is detecting what the view actually is if UIDevice returns an orientation of flat (non portrait or landscape).
Many applications have this issue. If the device is flat then any of the orientations is valid.
Your best bet is to use the [[UIDevice currentDevice] orientation] to know what the orientation is if possible for the cases where the orientation can be determined. But when it's flat, it'll just be whatever it was last.
How many times have you see people flick up their iPad to get the landscape orienation the right way around.
GOT IT!
I was able to do a work around by using
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
Even on view load this method is triggered if the orientation is not of UIInterfaceOrientationPortrait.
Even if the device is flat, it seems that there is a long enough delay for the orientation to correct itself and detect whether the UIView is in portrait or landscape mode.
EDIT:
When viewDidAppear is triggered by then, [self interfaceOrientation] has the correct value. So if you can wait until that method, you can also get it there.
I've got an iPad App with a TabBarController. Since iOS5 I'm note able anymore to get the correct orientation in the viedDidLoad or viewWillAppear when I start the app on the iPad in landscape. It always returns Portrait. When I ask for the orientation in viewDidAppear, everything is fine and correct. In iOS4 I was able to get the right orientation, but now I build for iOS5 ... not anymore.
Please. What can I do to get the right orientation on the iPad on startup?
This is how I get my orientation:
UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation;
Thanks!
If you are loading any viewcontroller before loading RootViewContoller then Orientation of RootViewController needs to be set before adding it to window. you may find answer HERE