My app does not support Portrait mode but at times it turning into portrait mode - orientation

My app does not support Portrait mode but at times it turning into portrait mode. I am using Xcode 5.02 & I am running my app on iOS7. I unchecked the portrait mode in the settings so that it does not support portrait, but at a point of time it is turning into portrait, I dont have any clue, any one to help me out, my app is master-detail base. This below code snippet in app delegate & dashboardNavController is UINavigationController
self.window.rootViewController = self.dashboardNavController;
[self.window makeKeyAndVisible];
if needed I am glad to provide more informations, Thanks in advance

Try this in ViewDidLoad
CGAffineTransform transform = CGAffineTransformMakeRotation(-M_PI/2);
self.view.transform = transform;
// Repositions and resizes the view.
// If you need NavigationBar on top then set height appropriately
CGRect contentRect = CGRectMake(0, 0, self.view.size.height, self.view.size.width);
self.view.bounds = contentRect;

Related

Is Apple using black magic to accomplish camera's preview orientation?

I have this AVFoundation camera app of mine. The camera preview is the result of a filter, applied by didOutputSampleBuffer method.
When I setup the camera I am following what apple did on one of their sample codes (CIFunHouse):
// setting up the camera
CGRect bounds = [self.containerOpenGL bounds];
_eaglContext = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES3];
_videoPreviewView = [[GLKView alloc] initWithFrame:bounds
context:_eaglContext];
[self.containerOpenGL addSubview:_videoPreviewView];
[self.containerOpenGL sendSubviewToBack:_videoPreviewView];
id<MTLDevice> device = MTLCreateSystemDefaultDevice();
NSDictionary *options = #{kCIContextUseSoftwareRenderer : #(NO),
kCIContextPriorityRequestLow : #(YES),
kCIContextWorkingColorSpace : [NSNull null]};
_ciContext = [CIContext contextWithEAGLContext:_eaglContext options:options];
[_videoPreviewView bindDrawable];
_videoPreviewViewBounds = CGRectZero;
_videoPreviewViewBounds.size.width = _videoPreviewView.drawableWidth;
_videoPreviewViewBounds.size.height = _videoPreviewView.drawableHeight;
dispatch_async(dispatch_get_main_queue(), ^(void) {
CGAffineTransform transform = CGAffineTransformMakeRotation(M_PI);
_videoPreviewView.transform = transform;
_videoPreviewView.frame = bounds;
});
self.containerOpenGL is a full screen view and is constrained to the four corners of the screen. Autorotation is on.
But this is the problem...
When I setup the GLKView and self.ciContext it is created assuming the device is on a particular orientation. If the device is on a particular orientation and I run the application, the previewView will fit the entire self.containerOpenGL area but when I rotate the device the previewView will be out center.
I see that Apple code works perfectly and they don't use any constraints. They do not use any autorotation method, no didLayoutSubviews and when you rotate the device, running their code, everything rotates except the preview view. And worse than that, my previewView appears to rotate but not their's.
Is this black magic? How do I they do that?
They add their preview view to a uiwindow and that is why it does not rotate. I hope this answers the question. If not I will continue to look through their source code.
Quote from source code.
we make our video preview view a subview of the window, and send it to the back; this makes FHViewController's view (and its UI elements) on top of the video preview, and also makes video preview unaffected by device rotation
They also add this
_videoPreviewView.enableSetNeedsDisplay = NO;
This may keep it from responding as well
Edit: It appears that now the preview rotates and the UI does as well so to combat this you can add a second window and send it to the back and make the main window clear and add the previewView to the second window with a dummyViewController that tells it not to autorotate by overriding the appropriate method. This will allow the preview to not rotate but the UI to rotate.

blank space above the bar?

I have a iphone app which is installed in iPad its UI(blank space about 20 pixels above navigation bar) is correctly displayed in ios6 while a blank space appears in ios7 in iPad.
I tried using the default images and using the methods
- (void) viewDidLayoutSubviews {
if (([[UIDevice currentDevice].systemVersion floatValue] >= 7.0)) {
CGRect viewBounds = self.view.bounds;
viewBounds.origin.y = -20;
self.view.bounds = viewBounds;
}
}
but no use.How do i fix it? It is not a universal app.
The problem is related on the way iOS7 draws the views, please rewfer to these guide to understand the problem:
Explaining difference between automaticallyAdjustsScrollViewInsets, extendedLayoutIncludesOpaqueBars, edgesForExtendedLayout in iOS7

IOS: size of view in iPad project with storyboard

I start a new project in xcode 5 for iPad; then in the project target I set application only for landscape mode (right and left)
In storyboard I set my first view in landscape and when I run it's in landscape mode correctly.
I do a clean.
But if I do this log:
NSLog(#" width:%f", self.view.bounds.size.width);
NSLog(#" height:%f", self.view.bounds.size.height);
I also tried:
NSLog(#" width:%f", self.view.frame.size.width);
NSLog(#" height:%f", self.view.frame.size.height);
the result is width: 768
and height: 1024
but it's wrong because I have a landscape orientation.
What's the problem?
Are you adding the NSLogs to viewDidLoad ? You have to let the view load completely before checking the dimensions. It should report correct dimensions in viewDidAppear.
Make sure you limit your device orientations like this:
I'm guessing you've done this, according to your question. Also make sure that your UIViewController classes override supportedInterfaceOrientations to return UIInterfaceOrientationMaskLandscape.

Photo album crashes in iPad2

I am presenting photo album and camera from a UIButton from a UIPopOverController. Both works fine when I present it in iPad1 running on iOS 5.1.
When I do the same thing in iPad2 running on iOS 6.0, the camera works fine but the photo album crashes as in the below image. Also note than the app is a landscape app.
The code Im using is
//imgPicker.contentSizeForViewInPopover = CGSizeMake(320, 500);
self.popOver = [[UIPopoverController alloc] initWithContentViewController:picker];
popOver.delegate = self;
[self.popOver presentPopoverFromRect:importFromPhotosBtn.frame
inView:importFromPhotosBtn
permittedArrowDirections:UIPopoverArrowDirectionAny
animated:YES];
Please someone point me out what went wrong. Im struck up with this for more than half a day. Any timely help is much more appreciated.
The UIImagePicker is supported on the portrait mode.
Your application supports only landscape mode, that causes the issue.
Solution:
Subclass UIImagePicker class
Implement shouldAutorotate in the subclass
- (BOOL)shouldAutorotate
{
return NO;
}
Use this subclassed UIImagePicker class for creating picker instead of UIImagePicker
Thanks for #Midhum MP's clue, the problem actually was the frame from which I presented the popOver.
The popOver size is 320 x 500 but I was presenting it from the rect containing (221, 360) as the origin, So the size messed up (500 + 360 which is greater than the iPad ht in landscape(768)).
But not sure why it runs in iPad1(iOS 5.1) and not in iPad2 (iOS 6)!
So, I just changed the presenting rect (such that it won't've such mess-ups) which works fine now. It fixed the issue.

Why is my ModalView displaying in portrait mode?

Hopefully somebody can point out what I'm doing wrong with my Splash screen here. The problem is that the screen is displaying in portrait mode, not landscape...
- (void)showSplash
{
UIView *modelView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 1024 , 748)];
UIViewController *modalViewController = [[UIViewController alloc] init];
[modelView setBackgroundColor:[[UIColor alloc] initWithPatternImage:[UIImage imageNamed:#"Splash.png"]]];
modalViewController.view = modelView;
[self presentModalViewController:modalViewController animated:NO];
[self performSelector:#selector(hideSplash) withObject:nil afterDelay:5.0];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}
Thanks in advance for the help.
Looks like you are writing app for iPad. If so, you have to support both landscape as well as portrait orientation otherwise Apple will reject it. I would suggest that you should use two different images. Image specifications are as follows:
Default-Landscape.png (1004 * 768)
Default-Portrait.png (748*1024)
(I am assuming that you are showing status bar if not add 20 pixels to height of an image)
That's it, create these images and add it to your project. And you are good to go. No Need to write any additional piece of code too..
And ya make it
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return YES;
}
You shouldn't rely on a function in your code to display the splash screen. Just define them as the previous answer from Sumit Lonkar explains.
If you do it in code, I believe at the start of the application the orientation is always considered as portrait, then the transition to the actual orientation is triggered. This explains why your code displays first as portrait and most likely there is nothing else in the code to handle rotation. Besides, the purpose of the splash screen is to display something while the app is loading, so if you put it in code you lose the purpose.
By doing it the Apple way you leave it to another Apple process that runs before looking at your code and it will work.
Regarding the orientation supported I have on my iPad some apps that support only landscape (TapZoo for example) so it should be ok with Apple.

Resources