How to force camera screen presenting in landscape mode - objective-c

I have a iPad application in Landscape orientation (iOS7), but when I present a UImagePickerViewController (Camera), this can be in portrait mode and need to avoid it.
Is there any way to lock this portrait orientation?
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
imagePicker.delegate = self;
imagePicker.sourceType =UIImagePickerControllerSourceTypeCamera;
imagePicker.mediaTypes = [NSArray arrayWithObjects:(NSString *) kUTTypeImage,nil];
imagePicker.allowsEditing = NO;
[self presentViewController:imagePicker animated:YES completion:NULL];
Thanks In advance.
Edit: I have followed the next iOS7 iPad Landscape only app, using UIImagePickerController and now the bars of the camera and preview picture taken appears in landscape mode, but if I take a photo with iPad in portrait orientation (app keeps on landscape orientation) the preview image rotates 90 degrees and 2 black sections appear on each side.
So, what I need is avoid this rotation in preview picture in the UIImagePickerViewController.
Does anyone have any idea?

Related

iOS 8 UIImagePickerController has black preview in Landscape mode

I am developing app for iPad, in Landscape mode during taking a snapshot from camera a black preview appears.While , UIImagePickerController works properly for Portrait mode.Thanks in advance.
this is my piece of code -
-(UIImagePickerController *)imagePicker{
if(!imagePicker){
imagePicker = [[UIImagePickerController alloc]init];
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
imagePicker.delegate = self;
}
return imagePicker;
}
[self presentViewController:self.imagePicker animated:YES completion:^{ }];
PS: Anybody knows about, "Contacts" default app of iOS device having this feature rotation of camera controls with respect to device orientation.Here, Camera preview looks fine for all orientation.Anybody knows its implementation.
if you are using Autolayout then you first Check for the co-ordinates and size of corresponding preview(UIimageview).

cameraOverlayView in ios7 hides default camera toolbar, but works in ios6

My code to place an overlay in the imagepicker works in iOS6, but not in ios7. In iOS6 the camera display fine; it appears that the overlay is slotted between the picker and the controls nicely. In iOS7, it seems that the overlay is placed on the very top layer, hiding the controls. I can still click on the take photo button though.
Is there anyway to put the camera controls back on top? Or is this a bug?
imagePicker =[[UIImagePickerController alloc] init];
overlayView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:imageString]];
imagePicker.cameraOverlayView = overlayView;
imagePicker.delegate=self;
imagePicker.title=#"Test";
imagePicker.showsCameraControls = YES;
[self presentModalViewController:imagePicker animated:YES ];
[imagePicker release];

Prevent shutter animation from appearing full screen when using cameraOverlayView [duplicate]

I have a transparent view with a rectangle drawn onto it using CoreGraphics.
When the camera launches the custom overlay view is above the shutter animation.
What you see is the standard camera shutter with the custom rectangle above it.
How do I get it to go in the right place, underneath the shutter animation? I've looked at other sample code but it's for OS 3.1 and doesn't seem to do anything differently.
Here's my code:
-(IBAction)cameraButton{
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerCameraDeviceRear]){
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
//Add the OverlayView with the custom Rectangle
CGRect overlayFrame = CGRectMake(0.0f, 0.0f, 320.0f, 480.0f);
OverlayView *overlayView = [[OverlayView alloc]initWithFrame:overlayFrame];
picker.cameraOverlayView = overlayView;
[overlayView release];
[self presentModalViewController:picker animated:YES];
[picker release];
}
}
On the iPad this problem doesn't exist, and the overlay view is behind the shutter animation by default. But on the iPhone, the overlay appears at front.
I've found a solution that worked for me.
You have to set your overlay view as a subview in this method:
- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated {
if (!viewController)
return;
UIView* controllerViewHolder = viewController.view;
UIView* controllerCameraView = [[controllerViewHolder subviews] objectAtIndex:0];
UIView* controllerPreview = [[controllerCameraView subviews] objectAtIndex:0];
[controllerCameraView insertSubview:self.overlayView aboveSubview:controllerPreview];
}
Hope it helps
Original source:
http://www.alexcurylo.com/blog/2009/06/18/uiimagepickercontroller-in-3-0/
You may not do anything else other than what you're already doing; if iOS decides to put your overlay view over the shutter, you'll just have to live with it (unless you want to risk getting rejected from the app store).
As an imperfect workaround, you could start your overlay with alpha=0 and then set alpha to 1 a second or two later. But there is no set time period that the shutter appears for before 'opening' (I think it depends on how long it takes to initialize the camera hardware), so sometimes your interface might not appear until late and sometimes might appear too early.
As of 4.3.3, the shutter animation is broken because elements are displayed on top, and then snap underneath when the animation starts. I've filed this as a Radar: http://openradar.appspot.com/radar?id=1204401
I answered a similar question here. What worked for me (in iOS 6) was setting the cameraOverlayView in navigationController:willShowViewController:animated.
- (void) navigationController:(UINavigationController*) navigationController willShowViewController:(UIViewController*) viewController animated:(BOOL) animated {
self.imagePickerController.cameraOverlayView = ...; // your camera overlay view
}

iOS camera UIView overlay full screen on iPad?

I'm trying to make an overlay on the camera mode on iPad. when the camera is in landscape mode, the overlay only covers 2/3 of the screen instead of the full screen. It is covering the whole screen in portrait mode however. My guess is the overlay could possibly be only showing in portrait size so that the overlay doesn't appear to be covering the full screen.
UIView *overlay = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
overlay.backgroundColor = [UIColor blueColor];
overlay.alpha = 0.3;
overlay.opaque = NO;
imagePicker.mediaTypes = mediaTypes;
imagePicker.cameraCaptureMode = UIImagePickerControllerCameraCaptureModePhoto;
imagePicker.modalPresentationStyle = UIModalPresentationFullScreen;
imagePicker.cameraOverlayView = overlay;
However can i make it to cover the whole screen? Any help will be appreciated.
Do manual setting for view frame. when it rotate to Portrait or Landscape.
For Portrait
CGRectMake(0,0,768,1024);
For Landscape
CGRectMake(0,0,1024,768);

In Cocoa-Touch Framework, is there any modal view in iPad like this?

Is there any model view like this on the iPad?
Yes, there is:
UIModalPresentationFormSheet
The width and height of the presented view are smaller than those of the screen and the view is centered on the screen. If the device is in a landscape orientation and the keyboard is visible, the position of the view is adjusted upward so that the view remains visible. All uncovered areas are dimmed to prevent the user from interacting with them.
For example:
UIViewController *viewController = [[UIViewController alloc] init];
viewController.modalPresentationStyle = UIModalPresentationFormSheet;
[self presentModalViewController:viewController animated:YES];
viewController.view.superview.frame = CGRectMake(0, 0, 540, 500); // this is important to do this after presentModalView
viewController.view.superview.center = self.view.superview.center;