How do you edit the buttons on UIImagePicker's camera with custom buttons like this (With Swift) :
it possible, if you would design your custom view base on your needs and add to UIImagePickerView as overlay view.
Overlay view take place exactly on native camera view so it would help to hide default buttons/component of native camera view.
var cameraUI = UIImagePickerController()
cameraUI.delegate = delegate
cameraUI.sourceType = .Camera;
cameraUI.delegate = self;
cameraUI.cameraOverlayView = getOverlayViewOnCamera()
controller!.presentViewController(cameraUI, animated: ture, completion:nil)
Now, Our overlay view is on camera so all buttons action are on our hand, so we have to now call object methods of UIImagePickerViewController according to button press.
Camera : takePicture()
Video : startVideoCapture() / stopVideoCapture()
Camera flash mode : cameraFlashMode
Camera Device : cameraDevice (Front, Rear)
Related
I'm trying to present a viewcontroller with a transparent background on both iOS 7 and iOS 8.
Just by changing the viewcontroller's modalPresentationStyle property to FormSheet I can get it working on iOS 7.1.
What I want is a universal way to that on ios7+
I have tried using other options to modalPresentationStyle, like: OverCurrentContext, CurrentContext and PageSheet.
I also tried to use the modalPresentationStyle.Custom but didnt have any success.
I have NavigationController if that helps in anything.
The code for the presenting view controller:
InfoViewController *info = [[InfoViewController alloc] initWithNibName:#"InfoViewController" bundle:nil];
[self presentViewController:info animated:YES completion:nil];
And the code for the viewDidLoad(which I think has a relevant part on this) of the presented ViewController:
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
self.modalPresentationStyle = UIModalPresentationStyle.PageSheet
}
I´m using swift and Xcode 6.
Here´s a screenshot of what I have now and of what I want, respectively:
Here's an example code: https://github.com/pbassut/TransBackgroundViewController
For those still with this problem before presenting the UIViewController set the modalPresentationStyle of the presented UIViewController to .Custom and it will work on iOS 8(Xcode 6.1). That is, you should set it in the presenting UIViewController
I've tried this solution and it works on both iOS 7 and 8:
if (UIDevice.currentDevice().systemVersion.integerValue >= 8)
{
//For iOS 8
presentingViewController.providesPresentationContextTransitionStyle = true;
presentingViewController.definesPresentationContext = true;
presentedViewController.modalPresentationStyle = UIModalPresentationOverCurrentContext;
}
else
{
//For iOS 7
presentingViewController.modalPresentationStyle = UIModalPresentationCurrentContext;
}
Note: Be aware of the difference between 'presentingViewController' and 'presentedViewController'.
None of the above worked for me. To get this working on iOS 10, I simply:
presented.modalPresentationStyle = .overFullScreen
presenting.present(presented, animated: true)
Then set the presented view controller's root view to have a transparent or semi transparent color. Don't change its alpha or all of its subviews will have the same alpha.
I was able to achieve this with no code:
In the storyboard, on the presenting view controller (i.e. before you segue to the one you want to be transparent), go to the attributes inspector. On that tab, there are checkboxes for "Defines Context" and "Provides Context". Check those.
On the segue, set it to be "Present Modally".
On the destination/presented view controller, go to the attributes tab. In the "Presentation" drop down, select "Over Current Context".
On the destination view controller, set it's view to have a clear background.
On the destination view controller, slap down 2 UIViews: One is your "transparent" one, and the other is your "content" one. Set the transparent one to have whatever alpha you like and put all your junk in the "content" one.
I achieve transparent with various styles in Swift 2.0 by following below steps. Analyse it to compatible with your code.
The transparent view controller(modal view controller) is launched by segue when a button click on main view controller.
Segue Settings:
In Main view controller:
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?)
{
let vc = segue.destinationViewController as! ModalViewController
vc.modalPresentationStyle = UIModalPresentationStyle.OverCurrentContext //All objects and view are transparent
}
Modal View Controller on StoryBoard:
If you need view and all objects are transparent
If you need view only transparent and over the objects are not transparent
On your Modal View Controller
override func viewDidLoad() {
super.viewDidLoad()
view.backgroundColor = UIColor.blackColor().colorWithAlphaComponent(0.8) //view only black coloured transparent
}
Sample Screenshots:
View and over the objects are transparent
View only transparent
For any other queries please comment here :)
If you confuse or more about with transparent view controller then watch my video tutorial for you on Youtube :D
iOS8+
Below code snippet will solve this problem in iOS8+
SecondViewController *secondViewController = [[SecondViewController alloc] init];
secondViewController.modalPresentationStyle = UIModalPresentationOverCurrentContext;
[self presentViewController:secondViewController animated:YES completion:nil];
I had a similar problem, i wanted to do something similar to the second screenshot that you present here (the brazilian/portuguese newspaper!)
I solved it like this. I inserted a UIView that covered the entire View Controller, then i went to the Attributes Inspector and i set the UIView's background color to black, with 50% opacity. Then, i inserted another UIView above the first one, and i worked on that one
If you change the view alpha, it will be applied to its subview, as it understands that the whole view is transparent.
The easy solution is change its colour with less opacity. Just select your background colour to custom
then select the RGB slider, choose your colour, and reduce the opacity.
I want to to use AVCaptureSession as I have to fit camera a view in a particular frame (I am not sure if I can fit the camera frame using UIImagePickerController). But I also want to show camera controls (Auto and front/back camera button), does anyone know how I can achieve this..? or will I have to use these as custom buttons.
If you want to use AVCaptureSession, you will have to do all camera controls of your own (adding some overlayview to your AVCaptureSession camera). You can use UIImagePickerController and transform your camera using cameraViewTransform, for example full screen camera transform:
#define CAMERA_TRANSFORM 1.32
camera.showsCameraControls = YES;
camera.navigationBarHidden = YES;
camera.toolbarHidden = YES;
camera.wantsFullScreenLayout = YES;
camera.cameraViewTransform = CGAffineTransformScale(camera.cameraViewTransform, CAMERA_TRANSFORM, CAMERA_TRANSFORM);
and for overlay you have property:
#property (nonatomic, retain) UIView *cameraOverlayView;
but i would recommend you to use just a addSubview to your UIImagePickerController view:
[camera.view addSubview:self.overlay.view];
I'd like to invoke the camera and display a live image in a small preview window (similar to below) that is embedded in a standard viewController. The code below creates the live reduced camera image, but I cannot see the other objects on the NIB file. Thoughts appreciated.
imagePicker = [[UIImagePickerController alloc] init];
//Setting the control source type as the Camera device.
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
//Camera display is off
imagePicker.showsCameraControls = NO;
imagePicker.navigationBarHidden = YES;
//Picking only the rear camera.
imagePicker.cameraDevice = UIImagePickerControllerCameraDeviceRear;
//Turning the camera flash off.
imagePicker.cameraFlashMode = UIImagePickerControllerCameraFlashModeOn;
// Make camera view partial screen:
imagePicker.cameraViewTransform = CGAffineTransformScale(imagePicker.cameraViewTransform, 0.5, 0.5);
// add subView
[self.view addSubview:imagePicker.view];
[imagePicker viewWillAppear:YES];
[imagePicker viewDidAppear:YES];
// Show the picker:
[self presentModalViewController:imagePicker animated:YES];
Without running the code, it looks like you are changing the live image, not the size of the view. So the original fullsize view is showing over the top of your other views.
Have you tried using camerOverlayView to overlay the viewcontrollers view on top of the live image?
cameraOverlayView
The custom view to display on top of the default image picker interface.
#property (nonatomic, retain) UIView *cameraOverlayView Discussion You
can use an overlay view to present a custom view hierarchy on top of
the default image picker interface. The image picker layers your
custom overlay view on top of the other image picker views and
positions it relative to the screen coordinates. If you have the
default camera controls set to be visible, incorporate transparency
into your view, or position it to avoid obscuring the underlying
content.
I created a simple application using UIImagePickerViewController for capturing from the camera, but I'd like to customize the interface for grabbing from the camera, such as adding some buttons.
UIImagePickerViewController doesn't allow this directly, so how would you create a custom view that allows for displaying the live camera feed and capturing from it?
The easy way is to continue to use UIImagePickerViewController but set showsCameraControls to NO and provide your own user interface using cameraOverlayView.
The more difficult (but more flexible) way is to use the AVFoundation classes (particularly AVCaptureVideoPreviewLayer and AVCaptureStillImageOutput) to construct your own camera.
Yes, 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];
You need to set the value of showCameraControls to NO and provide your own custom overlay view using the cameraOverlayView.
I'm developing an app that needs to take two pictures in a row. I'm currently using the iPhone camera but :
I would like to NOT have the cancel
button on the bottom left
I would like to NOT have the preview of my picture (with the blue
button "use").
What should I do ? Should I make my own camera ? I couldn't find an easy tutorial for a custom camera with only a "take picture" button...
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];
The easiest way to do it is to use UIImagePickerController with showsCameraControls set to NO and a custom view set in cameraOverlayView; this view can have whatever buttons you need on it. When touched, the button should call takePicture on the image picker, and when you're done just use dismissModalViewControllerAnimated: to dismiss the picker.