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];
Related
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.
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.
I need to show a small dialog on top of my existing views (so then can be seen). I've adjusted the size of my SmallTutorialDialog but when I load it it occupies the whole screen.
How can I adjust this ?
-(void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
SmallTutorialDialog *lvc = [[SmallTutorialDialog alloc]
initWithNibName:#"SmallTutorialDialog" bundle:nil];
[self presentModalViewController:lvc animated:NO];
[lvc release];
}
Simply, you can't. According to the iOS Class Reference:
Resizes its view and attaches it to
the view hierarchy.
Workaround:
Create a view that houses your small view controller and animate it (see CABasicAnimation) to obtain the desired effect.
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!
I currently have several view controllers and transitions set up throughout my app using:
ViewController2 *controller2 = [[ViewController2 alloc] initWithNibName:#"ViewController2" bundle:nil];
controller2.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
[self presentModalViewController:controller2 animated:YES];
[controller2 release]; controller2 = nil;
What I really want is when the vertical transition is made, I want an image of bubbles to travel up the screen with the transition. Is there anyway of adding an Image to these transitions. If not I would like to know how to create this effect as I have seen it in apps before.
Thanks in Advance,
Adam
Simple way would be to add a UIImageView the size of the view being animated, with your bubbles image set to it as a subview of that view. You can then remove it in the viewDidUnload or where appropriate in your code.