In my universal application, I am creating a camera overlay view over my camera interface. Note that My app is locked for portrait mode. However, when I change the interface orientation of iPad, the overlay also rotates with it. But i don't want that!
How to stop it from rotating with rotation in interface?
this is how the overlay looks in portrait on iPAD (with home button down):
And this is how rotates in landscape on iPAD (with home button on left):
Make sure you disable all but Portrait orientations in your app settings.
EDIT
You can also create a custom UIImagePickerController class like this:
#interface MyImagePickerController : UIImagePickerController
#end
#implementation MyImagePickerController
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
{
return toInterfaceOrientation == UIInterfaceOrientationPortrait;
}
- (BOOL)shouldAutorotate
{
return NO;
}
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return UIInterfaceOrientationPortrait;
}
#end
Related
For the app, the orientation is in portrait most of the time, but we have one view that needs to be set to landscape. I have this code to set it to landscape:
-(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return UIInterfaceOrientationLandscapeLeft;
}
- (UIInterfaceOrientationMask)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskLandscape;
}
I also have device orientation set to portrait and landscape left in the general tab for the app.
The issue is that the app will sometimes work properly but other times it will get stuck in a mix between portrait and landscape.
I have provided an image of what it looks like getting Stuck in transition. If I then reload the view it will work properly, it is only on the first time opening the view that it has a chance of failing.
I think you should set this in AppDelegate.m
- (UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(nullable UIWindow *)window {
if self.rotatble {
return UIInterfaceOrientationMaskLandscape
} else {
return UIInterfaceOrientationMaskPortrait
}
Might this is duplicated one, but I am not getting exactly what I want.
My application is only Portrait base and in which I want to show a Video file in MPMoviePlayerViewController only and only in Landscape mode. but unable to do that.
I've set my device orientation only Portrait and in which I wanna show movie direct in landscape mode. If any one did it then share it with me....thanks in advance
Is it possible once I defined my app is only in Portrait mode(through PLIST/ Development Info setting) and then I want to change Orientation from programing(ex. Landscape mode).???
In the project file, make sure you are supporting the Landscape Orientations
Now in all of your ViewControllers that should still be Portrait Only, add this code
- (BOOL)shouldAutorotate {
return NO;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return UIInterfaceOrientationPortrait;
}
- (NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskPortrait;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
When your MPMoviePlayerController view becomes fullscreen, it will be a new ViewController layered on top of everything else. So, it will be allowed to rotate according to the Supported Interface Orientations of the Project. It will not see where you forced the other ViewControllers into Portrait.
I am making game which supports only landscape orientation but I am also using a library to share my game video but that share screen require portrait orientation , If I don't enable portrait orientation my game got crash but If I enable portrait orientation to avoid this crash then my whole game become useless by becoming portrait as it is only for landscape.
This is my game Landscape View as shown by figures below,
This is the Library Portrait View to Share video
My Game View after sharing video from library
Please help me How can I enable portrait orientation for this library to avoid crash
and my rest of the app always remain in landscape and it never goes to portrait orientation.
Thanks
Add the following method to your application's AppDelegate.m file:
// IOS 6
-(NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {
return UIInterfaceOrientationMaskAll;
}
In both cases you must also make sure that you have added the landscape only orientation handling code to your game's main UIViewController.
// IOS 5
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
return UIInterfaceOrientationIsLandscape(toInterfaceOrientation);
}
// IOS 6
- (BOOL)shouldAutorotate {
return YES;
}
- (NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight;
}
Try to implement orientation methods to your view controller.
https://developer.apple.com/library/ios/featuredarticles/ViewControllerPGforiPhoneOS/RespondingtoDeviceOrientationChanges/RespondingtoDeviceOrientationChanges.html
I hope this help you.
In the view controller you want to support orientation override supportedInterfaceOrientations method.
I did like this...
-(NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationLandscapeLeft | UIInterfaceOrientationLandscapeRight;
}
I am building a landscape cocos2d-x game and while working on the iOS version I am realizing that a a progress hud (SVProgressHUD) shows on screen sideways as if it thinks the app is portrait.
In XCode I have Device Orientation set to Landscape right, then in my RootViewController I have:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return UIInterfaceOrientationIsLandscape( interfaceOrientation );
}
- (NSUInteger) supportedInterfaceOrientations{
return UIInterfaceOrientationMaskLandscape;
}
- (BOOL) shouldAutorotate {
return YES;
}
My game is correctly in landscape, but not the progress HUD. What am I missing?
I have an app that is always showed in portrait mode.
But in somewhere i have a media gallery that must support landscape.
The supported orientation by default in the project is portrait. Because of that the gallery is only showed in portrait mode.
If i change the project setting to show in portrait and landscape the gallery works fine but i can't control the other viewControllers to show only in portrait.
I tried several methods like shouldAutoRotate but no one worked.
Any ideia how to solve?
Regards
EDIT:
Solved :)
First i configured the project to support all orientation.
Then i added this method to the AppDelegate.m:
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
return UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskLandscape;
}
After this what i did was to block orientation in each view controller, less the one i want to have orientation in landscape and portrait.
Code to block orientation (iOS 7):
- (BOOL)shouldAutorotate
{
return YES;
}
- (NSUInteger)supportedInterfaceOrientations
{
return (UIInterfaceOrientationMaskPortrait);
}
Thanks to everyone that answered me :)
In my app for iPhone its only support the portrait view only, but as per requirement need to support landscape view only for on view, at that time I use following way and its help me :
In your app delegate .h
#interface PlayWithWSWithLibAppDelegate : NSObject <UIApplicationDelegate, UITabBarControllerDelegate> {
BOOL flagOrientationAll;
}
#property (assign) BOOL flagOrientationAll;
Add following method in your app delegate .m file
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window{
//NSLog(#"PlayWithWSWithLibAppDelegate -- supportedInterfaceOrientationsForWindow");
if([UICommonUtils isiPad]){
return UIInterfaceOrientationMaskAll;
}else if(flagOrientationAll == YES){
return UIInterfaceOrientationMaskAll;
} else {
return UIInterfaceOrientationMaskPortrait;
}
}
Implement following way in your view which you want to rotate in both portrait and landscape both for iPhone device
-(void)viewWillAppear:(BOOL)animated
{
self.tabBarController.delegate = self;
PlayWithWSWithLibAppDelegate *delegate = (PlayWithWSWithLibAppDelegate *) [[UIApplication sharedApplication] delegate];
delegate.flagOrientationAll = YES;
}
}
-(void)viewWillDisappear:(BOOL)animated
{
//NSLog(#"viewWillDisappear -- Start");
PlayWithWSWithLibAppDelegate *delegate = (PlayWithWSWithLibAppDelegate *)[[UIApplication sharedApplication] delegate];
delegate.flagOrientationAll = NO;
}
see this post also: How to set one of the screens in landscape mode in iphone?
You have to make another class in the same view Controller where you are presenting your media.
In that you can specify your orientation where it will support only landscape orientation only when you will present your media.
I am giving you an example of my app which supports only in landscape mode but as I took Image picker and it supports only in portrait mode so I changed the orientation for only that view.
#pragma mark - Image PICKER
#interface NonRotatingUIImagePickerController : UIImagePickerController
#end
#implementation NonRotatingUIImagePickerController
- (BOOL)shouldAutorotate
{
return YES;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return UIInterfaceOrientationPortrait ;
}
#end
Then when I used ImagePicker I used object of the class that i made.
So I define like below.
UIImagePickerController* picker = [[NonRotatingUIImagePickerController alloc] init];
So For Image Picker It showed only in portrait mode.
You just need to change Landscape instead of portrait if you want only Landscape Orientation for your particular view where you want to change it.
Hope this helps you.