How to open both camera and video - ios

How i can open both Video capture And and Image capture Camera from One Button like IPhone Default Camera where i can slide from video to image click. is their any third party for that please help?

You've to make your custom camera for that and handle the both cases check here.
or there is a third party that do the same check it.

Here is the answer that I was looking for we need to set mediaType if both bot photo and video mode is required in a single action.
let picker = UIImagePickerController()
picker.delegate = self
picker.sourceType = type
picker.mediaTypes = ["public.image","public.movie"]
picker.allowsEditing = true
present(picker, animated: true, completion: nil)
Happy Coding :)

Related

Setting iOS UIImagePickerController to Landscape mode for external display

I'm creating an app for an art installation which will mimic Apple's own camera app, but with slight modifications (slight video display parameters, front camera only, etc.). Everything is working for the most part, however I will have the camera connected to an external monitor, and therefore need it to display in landscape mode, not portrait mode. I have it connected via Lightning to HDMI.
I am using UIImagePickerController and not AVFoundation, because by default it does face detection which is identical to Apple's own (the yellow squares around the faces). I get the feeling that replicating the face detection in AV foundation would be a significant amount of trouble. However, UIImagePickerController simply refuses to display in landscape mode. This is the message in the reference about it:
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, with one exception. You can assign a custom view to the cameraOverlayView property and use that view to present additional information or manage the interactions between the camera interface and your code.
from: https://developer.apple.com/reference/uikit/uiimagepickercontroller
Is what I want to do still possible? I am already using a cameraOverlayView, however that so far has not fixed the problem? Can I just change things for HDMI display? Since I will not be submitting this app to apple, I don't particularly need to follow their standards as long as I can install it on my own iPhone 7 Plus running 10.1.1.
Here is my current code in case it helps:
let imagePicker = UIImagePickerController()
let myView = UIView(frame: CGRect(x: 0, y: 0, width: 100, height: 200))
myView.backgroundColor = UIColor(colorLiteralRed: 0.5, green: 1.0, blue: 0.2, alpha: 1)
myView.alpha = 0.1
imagePicker.delegate = self
imagePicker.sourceType =
UIImagePickerControllerSourceType.camera
imagePicker.cameraDevice = UIImagePickerControllerCameraDevice.front
imagePicker.mediaTypes = [kUTTypeImage as String]
imagePicker.allowsEditing = false
imagePicker.videoQuality = UIImagePickerControllerQualityType.type640x480
//imagePicker.showsCameraControls = false
imagePicker.cameraOverlayView = myView
imagePicker.modalPresentationStyle = UIModalPresentationStyle.currentContext
self.present(imagePicker, animated: true,
completion: nil)

Whats the `allowsEditing` flag good for?

I wanted to use UIImagePickerController to select an image, crop it to a given size (using a given aspect ratio) and to set it on my UIImageView.
So I did the following:
let picker = UIImagePickerController();
picker.modalPresentationStyle = .currentContext;
picker.allowsEditing = true;
picker.delegate = self;
self.present(picker, animated: true);
When I know try it I can select an image and I get leaded to the "move and scaling" view of iOS. But actually.... I have no crop frame and also moving and scaling is a little bit "strange" and it does not matter how I move or scale the image, the result is always the same. The result is always just showing a small section of the original picture (top left corner).
So what is the editing mode good for at all if it has zero functionality?

Wrong pin entry, snap a photo without presenting the camera on screen

I am trying to have my application take a photo of an "intruder" when the wrong pin is entered into my application.
I have set up the UIImagePickerController(Below) and can make the application display the camera and take photos with no problem what so ever.
picker = UIImagePickerController() //make a clean controller
picker.delegate = self
picker.allowsEditing = false
picker.sourceType = UIImagePickerControllerSourceType.Camera
picker.cameraCaptureMode = .Photo
presentViewController(picker,animated: true,completion: nil)
Then i proceed to attempt this as to make the new set up for the picker
picker.showsCameraControls = false
I know that has to be set to false to call picker.takePicture()
Now I dont want to present the picker viewController and be able to call takePicture() but this is not hitting the delegate method of didFinishPickingMediaWithInfo.
I have tried using a custom overlay as well, but to no avail of 100% hiding the camera.
How do I go about not showing or displaying the camera on screen and being able to grab this picture of the front camera?
I have permission for access as well.
The other question posted on here of a similar topic does not solve this issue for help in swift.
Is the only way possible using AVFoundation?
If so, any help would be appreciated

UIImagePicker that only fills the top half of the screen

I'm trying to present a camera on the only the top half of my screen and my code isn't resizing the camera properly. I'm trying to add a view to the top half of my screen and then have the camera's cameraOverlayView property conform to that view's frame. Regardless of what I try however, the camera still appears in full screen mode. If someone can tell me what I'm doing wrong I'd really appreciate it. Thanks!
// Setting Up The Camera View
cameraView = UIView(frame: CGRectMake(0.0, 0.0, view.bounds.width, view.bounds.width))
view.addSubview(cameraView)
// Setting Up The Camera
var cam = UIImagePickerController()
cam.delegate = self
cam.allowsEditing = false
cam.videoMaximumDuration = 7
cam.videoQuality = UIImagePickerControllerQualityType.TypeMedium
cam.mediaTypes = UIImagePickerController.availableMediaTypesForSourceType(UIImagePickerControllerSourceType.Camera)!
cam.sourceType = UIImagePickerControllerSourceType.Camera
cam.cameraDevice = UIImagePickerControllerCameraDevice.Rear
cam.cameraCaptureMode = UIImagePickerControllerCameraCaptureMode.Video
cam.cameraFlashMode = UIImagePickerControllerCameraFlashMode.Off
cam.showsCameraControls = true
cam.cameraOverlayView = cameraView
cam.cameraOverlayView?.frame = cameraView.frame
camera = cam
self.presentViewController(camera, animated: false, completion: nil)
I do not think what you want to do can be accomplished using a UIImagePickerController. The AVFoundation is what you want to use if you want complete customization of the camera. You can read about it here https://developer.apple.com/library/ios/documentation/AudioVideo/Conceptual/AVFoundationPG/Articles/04_MediaCapture.html#//apple_ref/doc/uid/TP40010188-CH5-SW2.
P.S. It is not the simplest framework to use

Camera with Custom View

My Application uses camera, I would like to add overlay over the camera preview. For example, I want to use a picture frame when I use Camera, also I would like to add a custom bar for camera operations. Kindly help me to do the same.
You might be trying using UIImagePickerController. But I know this one solution to your problem. You can do it easily using AVCamCaptureManager and AVCamRecorder classes. Apple has a demo program build on its developer site here. It is named AVCam. In simple words what it does is when you click to open the camera, it calls the classes and methods which are responsible for opening the iPhone's camera and record video or capture audio. It calls the same classes which are called by UIImagePickerController. So your camera will open and start taking input.
Now, if you open the xib file of that AVCam project, you'll find a small UIView object. This view is responsible for displaying the camera's feed. You can resize that view as per the size you want and the camera's input will be displayed in that much area. You can also put the frame image around it as per your choice.
It worked for me when I wanted to resize the camera's input feed and capture photos. I hope it works for you as well.
Create a UIImagePickerController from code, adjust its properties, add an overlay onto it, and with you controller, control whatever you want on that overlay : custom controls, overlaying images, etc...
That gives something like this :
self.picker = [[UIImagePickerController alloc] init];
self.picker.sourceType = UIImagePickerControllerSourceTypeCamera;
self.picker.cameraCaptureMode = UIImagePickerControllerCameraCaptureModePhoto;
self.picker.cameraDevice = UIImagePickerControllerCameraDeviceRear;
self.picker.showsCameraControls = NO;
self.picker.navigationBarHidden = YES;
self.picker.toolbarHidden = YES;
self.picker.wantsFullScreenLayout = YES;
// Insert the overlay
self.overlay = [[OverlayViewController alloc] initWithNibName:#"Overlay" bundle:nil];
self.overlay.pickerReference = self.picker;
self.picker.cameraOverlayView = self.overlay.view;
self.picker.delegate = self.overlay;
[self presentModalViewController:self.picker animated:NO];
OverlayViewController is the controller that you must write to control everything you add onto the overlay.
pickerReference is a property you can keep to send orders to the camera. For example, you could call the following from an IBAction coming from a UIButton placed onto the overlay :
[self.pickerReference takePicture];
Read the UIImagePickerController Class Reference, that's right in the documentation…
There are properties for this, especially the cameraOverlayView and showsCameraControls properties.
So you can hide the controls, provide a custom overlay view, and add subviews to this custom view to add custom buttons, frames, etc.
Swift 3 version for answer from Oliver:
self.picker = UIImagePickerController()
self.picker.sourceType = .camera
self.picker.cameraCaptureMode = .photo
self.picker.cameraDevice = .rear
self.picker.showsCameraControls = false
self.picker.isNavigationBarHidden = true
self.picker.isToolbarHidden = true
// Insert the overlay
self.overlayViewController = self.storyboard?.instantiateViewController(withIdentifier: "Overlay") as! OverlayViewController
self.picker.cameraOverlayView = self.overlayViewController.view
self.picker.delegate = self.overlayViewController
self.navigationController?.present(self.picker, animated: true, completion: nil)
OverlayViewController protocols:
class OverlayViewController: UIViewController, UIImagePickerControllerDelegate, UINavigationControllerDelegate

Resources