Issue with Landscape orientation in iPhone - ios

I am having an app in which is in Landscape mode.
As I am opening photo library from one of my views I want that view in portrait mode because photo library can not be opened in Landscape mode.
So I selected Portrait from my settings and used the below code to lock the Portrait orientation for all the views except photo library view.
This works fine for all the views Except the first main view controller when launches the app.
I use the below code.
For opening Image Picker in Portrait mode.
#interface NonRotatingUIImagePickerController2 : UIImagePickerController
#end
#implementation NonRotatingUIImagePickerController2
- (BOOL)shouldAutorotate
{
return NO;
}
#end
For locking the other views in landscape mode.
-(BOOL)shouldAutorotate
{
return YES;
}
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight ;
}
I works for all my view controllers except my first view controller when the app launches.
How can I solve this?
Please help me.
Thanks in advance.

Related

Wrong UI orientation on UIImagePickerController when entering camera first time

I have wrong UI orientation on UIImagePickerController when entering camera first time on iPad. Device in landscape but UIImagePickerController in portrait.
That how it's looks like
After device rotation everything is ok - UIImagePickerController gets correct UI orientation.
I have
- (UIInterfaceOrientationMask)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskAll;
}
and
- (BOOL)shouldAutorotate {
return YES;
}
Ok, I found an answer.
The presenting controller(UIViewController) has a property called modalPresentationStyle and it was set as UIModalPresentationFullScreen.
To resolve my problem I just set it as UIModalPresentationOverFullScreen.
presentingController.modalPresentationStyle = UIModalPresentationOverFullScreen;
Thats all.

Specified Orientation Not Displaying Correctly on iPad

I have a universal iOS (7.1+) app that I would like to only support portrait orientation for most views. I would like 1 view to autorotate.
The application is a navigation based application (i.e. the base view is a UINavigationViewController). In the project editor under Deployment Info I have checked portrait, landscape left and landscape right as the supported orientations.
I then restricted the autorotation of the app by implementing the -(BOOL)shouldAutorotate method and the - (NSUInteger)supportedInterfaceOrientations in my base navigation controller. As I understand it, this will restrict the orientation in any view displayed by the navigation controller.
- (BOOL)shouldAutorotate {
return YES;
}
- (NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskPortrait;
}
The view I would like to autorotate I present modally. In the view controller that I present modally I also set -(BOOL)shouldAutorotate and - (NSUInteger)supportedInterfaceOrientations.
- (BOOL)shouldAutorotate {
return YES;
}
- (NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight | UIInterfaceOrientationMaskPortrait;
}
This solution works fine on iPhone! The one modal view rotates as expected and the other views inside the However, the same view using the same code does not rotate on the iPad. I am confused as to why it works on the iPhone and not on the iPad. It seems to me that since it is the exact same view controller that it should rotate on both.

InAppSettingKit auto rotate issue

I am using IASK in my app, and I just found a problem. That is when I'm going to change my device orientation, and the main viewcontroller is working well (both iOS 5 & 6). But in the IASK view controller it doesn't work! In addition, the viewcontroller always splash flips the view when I press the settings button to get into the IASK view controller. I am trying to figure out what's wrong in my code. I did add both view orientation methods for iOS 5 & 6 into IASK view controller as well, but it still doesn't perform correctly.
Does anyone know how to solve this kind of problem?
//ios5 autorotate
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
if ((interfaceOrientation==UIInterfaceOrientationPortrait)||(interfaceOrientation==UIInterfaceOrientationPortraitUpsideDown)) {
return YES;
}
else return NO;
}
//ios6 autorotate
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskPortraitUpsideDown;
}
- (BOOL)shouldAutorotate
{
return YES;
}

iOS 6 Orientation with NavigationController

I am currently developing an application that works with iOS 5 and iOS 6.
Most of my views are only on Portrait orientation except for 1.
RotationNavigationController : Main UINavigationController that overrides supportedInterfaceOrientation and shouldAutorotate.
PageViewController : Pushed in RotationNavigationController and is displayed in Portrait orientation only.
ImageViewController : Pushed after PageViewController. Is displayed with UIInterfaceOrientationMaskAllButUpsideDown.
Here's what I have in the ImageViewController's ViewDidLoad
- (void)viewDidLoad
{
// currentMask is the value returned by supportedInterfaceOrientation
[(RotationNavigationController*)self.navigationController setCurrentMask:UIInterfaceOrientationMaskAllButUpsideDown];
[(RotationNavigationController*)self.navigationController setShouldAutorotate:YES];
}
And when I popViewController from ImageViewController in landscape, I get back to PageViewController in landscape mode too whereas PageViewController only supports Portrait orientation.
Of course, I reset the mask in the ImageViewController's viewWillDisappear to Portrait.
Is there a way for PageViewController to remain in Portrait orientation ?
Thanks for the link emrys57. I found out the solution down there, and it was quite trivial in the end :
In RotationNavigationController, just add the following method :
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return UIInterfaceOrientationPortrait;
}

iOS 6 orientation issues

I have an application which normally is a portrait app and only show landscape view for one UIViewController. It works fine until the new iOS 6 is released.
I really don't understand how orientation works in iOS 6. So I wrote a testing app. Here is what I did:
Set the orientation of the application to support all orientations.
I'm using story board. The rootViewController is embedded in UINavigationController which is in portrait.
The code in rootViewController:
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskPortraitUpsideDown;
}
When I clicked the Open bar button, I'll push another (SecondViewController) view controller which supposed to be in landscape mode:
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight;
}
Although this method is called correctly, the second view controller is always also in portrait mode.
Can anybody give me some suggestions? Thanks
Here is my solution:
In second view controller's viewDidLoad:
- (void)viewDidLoad
{
[super viewDidLoad];
UIViewController *viewController = [[UIViewController alloc] init];
[self presentViewController:viewController animated:NO completion:^{
[viewController dismissViewControllerAnimated:NO completion:nil];
}];
}
This will force the second view to rotate to landscape orientation which solved my problem. And it works for iOS 5 and 6.
For iOS-6, I have done this. It is running fine
- (NSUInteger)supportedInterfaceOrientations{
return UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskLandscapeLeft;}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation{
return UIInterfaceOrientationLandscapeLeft;}
In second View
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation{
return YES;}
I think that best solution is to stick to official apple documentation. So according to that I use following methods and everything is working very well on iOS 5 and 6.
In all of your ViewControllers override following methods.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return UIInterfaceOrientationIsPortrait(interfaceOrientation);
}
Methods for iOS 6, first method returns supported orientation mask (as their name indicate), you can change it into Landscape or what suites you best.
-(NSInteger)supportedInterfaceOrientations{
return UIInterfaceOrientationMaskPortrait; //UIInterfaceOrientationMaskPortrait or LandscapeLeft ...
}
second one thats tells your VC which is preferred interface orientation when VC is going to be displayed.
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return UIInterfaceOrientationPortrait; //tells your VC in which orientation it should be presented, if you set Porttrait it would be in Portrait or otherwise ...
}
This solution is working smooth, I dont like the idea of creating macros and other stuffs, that goes around this simple solution.
Hope this help...

Resources