UIImagePickerController fullscreen - iphone

i'm using the UIImagePickerController to show the camera view in my main view, calling it with this code:
self.picker = [[UIImagePickerController alloc] init];
self.picker.sourceType = UIImagePickerControllerSourceTypeCamera;
self.picker.cameraDevice = UIImagePickerControllerCameraDeviceRear;
self.picker.showsCameraControls = NO;
and i have a self made toolbar in my storyboard, to manage some camera's functionality.
What happens is that when the app loads, the camera seems to overlay my toolbar, going in fullscreen and hiding my buttons. Why this happens?

It's normal the UIImagePickerController is ment to run full screen. You can an extra overlay view to the cameraOverlayView property to show you own controls.

Related

Fitting a UIImagePicker inside a navigation controler?

I'm making an application that uses the iphone camera to detect the changing brightness of the video stream. The video feed should be mid-way through a trail of views under the navigation controller. On pressing a button on this view, the user should see a view that displays the average brightness of the video stream.
I am having quite a lot of trouble getting the UIImagePicker to display in the right way. I've found that it is not possible to output it to a nested UIView - instead, the overlay for the camera should be set to display any extra functionality. I need this overlay to be part of my navigation controller.
I have the following code inside LuxMeterController:
- (void)viewDidLoad
{
[super viewDidLoad];
if (self.tst != YES) {
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
picker.showsCameraControls = NO;
picker.navigationBarHidden = YES;
UIStoryboard* sb = [UIStoryboard storyboardWithName:#"MainStoryboard" bundle:nil];
LuxMeterController* vc = [sb instantiateViewControllerWithIdentifier:#"cameraVc"];
vc.tst = YES;
picker.cameraOverlayView = vc.view;
[self presentModalViewController:picker animated:NO];
}
}
So first, the view is loaded - it initializes the camera and displays it as a modal view. The overlay of the camera is set to a second instance of LuxViewController - this one doesn't render a new camera as tst == YES.
This sort of seems to work - I have a video feed with a full-screen view as its overlay.
My problem is that as the overlay is not part of the hierarchy in the storyboard, it doesn't have UI elements (titlebar, back button,etc) that come from the navigation controller.
How do I get the overlay to sit inside the navigation controller? Or is this the wrong approach to take? How can I get a videostream to sit inside the navigation controller hierarchy, and to have overlay buttons that can move to a view further down the hierarchy?
I've only been doing objective-c and iphone development for a very short period of time, so I might be missing something obvious. If there is a better approach, I'd like to know about it.

UIImagePicker Shows blank when application in landscape

I am using navigation based application here when i call UIImagePicker then it show blank when the screen is in landscape but this shows correctly when the screen in portrait.
How can i change screen to portrait when its in landscape.
I using the code to call photo album is
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
picker.delegate = self;
[self presentModalViewController:picker animated:YES];
[picker release];
Edited:
Actually i am using TabBarController Which was pushed from another view using the concept of navigationController then when i tried to call UIImagePickerController when it is in landscape then shows blank.
But without TabBarController UIImagePickerController works perfect(Automatically rotate to portrait)..
So how could i call UIImagePickerController when in landscape in TabBarController.
Thanks..
If this happens in a UIViewController then do the following so that the view is never rotated:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return NO;
}
if u want to forcefully rotate in portrait use
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation==UIInterfaceOrientationPortrait||UIInterfaceOrientationPortraitUpsideDown)
}
UIImagePickerController is portrait-only, see the documentation:
Important: The UIImagePickerController class supports portrait
mode only. This class is intended to be used as-is and does not
support subclassing. The view hierarchy for this class is private and
must not be modified [...]

UIImagePickerController within a UIView

I have a little iOS project/test i am performing where i am calling an UIImagePickerContoller with the source set to the iPhones camera.
I am wanting to load this "live" camera into a smaller UIView box in my interface. I am getting the camera to load and show up, but not in the UIView. Here's the code I am working with :
- (void)viewDidAppear:(BOOL)animated {
UIImagePickerController *scope = [[UIImagePickerController alloc] init];
[scope setSourceType:UIImagePickerControllerSourceTypeCamera];
[scope setShowsCameraControls:NO];
[scope setEditing:NO];
[scope setNavigationBarHidden:YES];
[cameraDisplayView addSubview:scope.view];
[scope viewWillAppear:YES];
[super viewDidAppear:YES];
}
You need to use the cameraOverlayView property to draw other views on top of the camera view, not the other way around.
See the documentation for UIImagePickerController. You cannot force the camera picker controller into a UIView, you have to draw on top of the camera picker controller.
(And then you could set one of you overlaying views to clearColor to get a window to the camera controller.)
Set your imagepickercontroller frame size to your parent view like this:
scope.view.frame=CGRectMake(0, 0, cameraDisplayView.frame.size.width, cameraDisplayView.frame.size.height);
and than add your imagepickercontroller into your view.
[cameraDisplayView addSubview:scope.view];

iPhone: UIImagePickerController - standard zoom control doesn't work

I have a UIImagePickerController that is presented as a modal view controller. This works fine, except for when I try to add anything to the camera overlay view.
As soon as I modify the camera overlay view, the default zoom control stops working (although tap to focus still works). If I tap on the view, the zoom slider appears, but I am not able to slide it up and down like usual.
Here's the code I'm using:
imagePickerController = [[UIImagePickerController alloc] init];
imagePickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
imagePickerController.allowsEditing = NO;
imagePickerController.delegate = self;
imagePickerController.showsCameraControls = YES;
imagePickerController.wantsFullScreenLayout = NO;
[imagePickerController.cameraOverlayView addSubview:overlayView];
[self presentModalViewController:imagePickerController animated:YES];
Has anyone had a similar problem or can see what I'm doing wrong? I know it should work, as I've seen it on other apps that also use the default camera controls.
Thanks :)
After a lot of mucking round I've finally come across a solution. Don't use the cameraOverlayView property, instead add a subview to the UIImagePickerController with a frame of size CGRectZero.
In the following example, overlayView is a custom subclass of UIView which draws an image and passes touches through to the next responder:
OverlayView *overlayView = [[OverlayView alloc] initWithFrame:CGRectZero];
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
{
imagePickerController = [[UIImagePickerController alloc] init];
imagePickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
imagePickerController.allowsEditing = NO;
imagePickerController.delegate = self;
imagePickerController.showsCameraControls = YES;
[imagePickerController.view addSubview:overlayView];
statViewController.imagePickerController = imagePickerController;
}
-
And then, everything just works. Not sure if adding a subview to UIImagePickerController is documented and ok with Apple, but heaps of other apps use this (or a similar workaround) so shouldn't cause any submission problems.

How to add UIImagePickerController as a sub view instead of Modal View

I have a segment controller on one of my views and now on the 0th index of segment controller I want to add UIImagePickerController (for showing camera view to user) by adding as sub view and not by ModalViewController. Right now the view gets loaded but It does not show any camera view. I am able to show the camera view by presentModalViewController and passing its object.
Here's the code--
if(segmentedControl.selectedSegmentIndex==0)
{
UIImagePickerController *cameraView = [[UIImagePickerController alloc] init];
cameraView.sourceType = UIImagePickerControllerSourceTypeCamera;
cameraView.showsCameraControls = NO;
//[self presentModalViewController:cameraView animated:YES]; //Working
[self.view addSubview:cameraView.view]; // Not Working
}
[self.view addSubview:picker.view];
[picker viewWillAppear:YES]; // trickery to make it show
[picker viewDidAppear:YES];
You get a white bar at the top as side effect since UIImagePickerController is not intended to be used with it.
You should avoid doing this, it is not recommended and could lead to unwanted side effects.
As stated on the documentation (https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIImagePickerController_Class) you cannot add it as a subview, you should present it as a new controller
Here a piece of the doc:
On iPhone or iPod touch, do this modally (full-screen) by calling the
presentViewController:animated:completion: method of the currently
active view controller, passing your configured image picker
controller as the new view controller.
Hope this helpes!