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.
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 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];
I am new to Iphone development. I am working on an application which involves two views. I have a camera button in view one which opens up the default Iphone camera. This is achieved by having this code in the IBAction for camera button in ViewOneController:
UIImagePickerController *picker =
[[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = NO;
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
[self presentModalViewController:picker animated:YES];
[picker release];
The view controller for the first view is also the UIImagePickerControllerDelegate for the camera. When the picture is clicked and the camera view returns to the function imagePickerController:didFinishPickingWithMediaInfo where I do this:
(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
[picker dismissModalViewControllerAnimated:YES];
[self presentModalViewController:ViewTwoViewController animated:YES];
}
So basically all I am trying to achieve is from viewone click "take picture" ---> Open camera --> after camera is done jump to view two. Quite simmilar to what it is in the flickr app. However after I take the picture from camera my app returns to view one and view two is not shown. What am I missing here?
Also from a conceptual perspective I guess IOS keeps a stack of views for any app. When presentModalViewController is called the view is shown and it is added to the stack and when dismissModalViewController is called the view is removed from the stack and the parent view is show. Is that right?
Thanks.
You probably need to put the call to [self presentModalViewController:ViewTwoViewController animated:YES] in viewWillAppear which will be called after the picker view has been removed.
You probably also need to surround the call with some check to only present viewTwo when applicable.
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!
So I have a modal view displaying in my app that has a little info for the user to fill out. The problem is that when the device is rotated, some animation occurs, but only in the frame. The form itself does not rotate. All the autorotate options are set to YES. I am displaying it when the user clicks on a field in a popover. This makes me suspect it has something to do with that but I am not sure. It is bizzare because if the device is in either view and then the modal window is displayed, it is fine. It only happens when the device is rotated in the modal view. Does anyone have any idea what may be causing this behavior when the device is rotated? Thanks!
Here is a snippet that is handled in the popover view controller:
if (currentLevel == 1 && businessOrLocation == 0){
if(tbsViewController == nil)
tbsViewController = [[BusinessFilteredViewController alloc] initWithNibName:#"BusinessFilteredView" bundle:[NSBundle mainBundle]];
NSMutableArray *tempBusiness = [[NSMutableArray alloc] init];
for (id theKey in appDelegate.groupedBusiness) {
NSMutableArray *tempArr = [appDelegate.groupedBusiness objectForKey:theKey];
[tempBusiness addObject:tempArr];
}
tbsViewController.businessOrLocation = businessOrLocation;
tbsViewController.modalPresentationStyle = UIModalPresentationFullScreen;
tbsViewController.modalTransitionStyle = UIModalPresentationFullScreen;
[self presentModalViewController:tbsViewController animated:YES];
}
I ran into this problem as well. The fundamental problem is that popover controllers cannot present modal views—it seems that case wasn’t properly considered or designed for. In my situation, it was easy enough to work around. I just extended the delegate protocol for my popover-hosted view controller. The main view sets itself up as the delegate to the popover view, and takes responsibility for displaying and dismissing the modal views the user requests from within the popover.
Since I already had a delegate protocol to cleanly dismiss the popover view when the user clicks “done” it was only a small stretch to get autorotation working the way I wanted it to. Here are some snippets:
#protocol InfoViewControllerDelegate <NSObject>
#optional
// Implement this to close the info view once the user clicks done.
- (void)infoViewDidFinish:(InfoViewController *)view;
// Implement this method if the delegate launched us as a popup view and must therefore
// take responsibility for diplaying help.
- (void)infoViewDidRequestHelp:(InfoViewController *)view;
#end
And in my main iPad view which presents this popup view:
#pragma mark - InfoViewControllerDelegate methods
- (void)infoViewDidFinish:(InfoViewController *)view {
[self hideInfo:self];
}
- (void)infoViewDidRequestHelp:(InfoViewController *)view {
[self hideInfo:self]; // Close the info view first
HelpViewController *help = [[HelpViewController alloc] init];
help.delegate = self;
[self presentModalViewController:help animated:YES];
[help release];
}
To make life simple for cases where I am launching the info view outside of a popup view (for example, on the iPhone, it is a simple modal view), it checks to see if the delegate handles the modal subviews, and if not, handles them itself. That way I didn’t need to change the iPhone base controller at all, since autorotation already worked fine there. Here’s the “Help” button action in the info view controller, showing how I did that:
- (IBAction)help:(id)sender {
if ([delegate respondsToSelector:#selector(infoViewDidRequestHelp:)]) {
[delegate infoViewDidRequestHelp:self];
} else {
HelpViewController *help = [[HelpViewController alloc] init];
help.delegate = self;
[self presentModalViewController:help animated:YES];
[help release];
}
}
With this code in place, my entire interface autorotates smoothly on both devices, whether or not popup views were involved.
Just so i understand correctly... You are displaying a popover and inside that popover if the user taps a certain element then you are displaying a full screen modal view controller? Vie never tried that before and it seems odd for two reasons.
First it seems jarring to the user in my opinion. The popover gives you a nice, integrated UI and the modal takes you away.
More importantly though, your popover view controller doesn't really have authority over the whole screen so presenting a full screen modal from a popover just seems inherently wrong.
I would suggest you display a nav controller in the popover controller and instead of presenting the new view controller modally over the whole screen just push it on to the nav controller in the popover and keep the user inside the popover.
If that doesn't really work for you, then I would suggest reviewing your UI needs and redesigning the layout.
I am guessing that you implemented - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation in BusinessFilteredViewController and returns YES
Could you check that you add more than 1 subviews to application window . If so, try to create container UIViewController for all viewControllers that you want to add to window.