cameraOverlayView not applying - ios

When I try and apply a cameraOverlayView to UIImagePickerController, it doesn't show up. I have read through some documentation on how to apply this, and my code all looks correct. If someone could explain why my overlay isn't starting, I would really appriciate it.
//Start the camera up
UIImagePickerController *imageViewPickerController = [[UIImagePickerController alloc] init];
//Hide default UI elements
imageViewPickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
imageViewPickerController.showsCameraControls = NO;
imageViewPickerController.navigationBarHidden = YES;
imageViewPickerController.toolbarHidden = YES;
//Start the button overlay
UIView *btnView = [[UIView alloc] initWithFrame:imageViewPickerController.view.bounds];
btnView.backgroundColor = [UIColor whiteColor];
btnView.alpha = 0.3;
btnView.clipsToBounds = YES;
//Add a button to the overlay
UIButton *snapButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 1024, 1024)];
snapButton.backgroundColor = [UIColor blackColor];
[btnView addSubview:snapButton];
//Overlay button view
imageViewPickerController.cameraOverlayView = btnView;
//Fix for iPhone 5 and make fullscreen
CGAffineTransform translate = CGAffineTransformMakeTranslation(0.0, -55.0);
CGAffineTransform scale = CGAffineTransformMakeScale(1.333333, 1.333333);
CGAffineTransform rotate = CGAffineTransformMakeRotation(DEGREES_RADIANS(180));
CGAffineTransform transform = CGAffineTransformConcat(translate, scale);
transform = CGAffineTransformConcat(transform, rotate);
imageViewPickerController.cameraViewTransform = transform;
//Let's present it all
[self presentViewController:imageViewPickerController
animated:NO
completion:NULL];
SOLUTION:
I found the solution: it was both merging in Visput's suggestion, and fguchelaar's. I then removed the btnView.alpha = 0.3 and replaced it with btnView.opaque = NO; and that did the trick. Messed around with colors and now my overlay is working perfectly.

Frame of your overlay view has zero size:
UIView *btnView = [[UIView alloc] initWithFrame:CGRectZero];
Change it like this and you will see it:
UIView *btnView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 1024, 1024];
Update:
Also enable clipsToBounds flag: btnView.clipsToBounds = YES;

Related

Add Gesture to UIImagePickerController cameraOverlayView

I have a customed overlay view for my UIImagePickerController.
I want to add an UITapGestureRecognizer in this overlay view in order to draw a circle and focus the camera.
But once I added the gesture, my method is never called and I don't understand why.
Here is my code:
// Overlay view
UIView *overlay = [[UIView alloc] initWithFrame:self.view.frame];
// TapGesture
UITapGestureRecognizer *stabilisateurGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(Stabiliser:)];
stabilisateurGesture.numberOfTapsRequired = 1;
[overlay addGestureRecognizer:stabilisateurGesture];
// UIImagePickerController
pickerCamera = [[UIImagePickerController alloc] init];
pickerCamera.sourceType = UIImagePickerControllerSourceTypeCamera;
pickerCamera.delegate = self;
pickerCamera.cameraFlashMode = UIImagePickerControllerCameraFlashModeOff;
pickerCamera.modalPresentationStyle = UIModalPresentationFullScreen;
pickerCamera.showsCameraControls = NO;
pickerCamera.cameraOverlayView = overlay;
And here the gesture method:
- (void)Stabiliser:(UITapGestureRecognizer *)gesture {
CGPoint point = [gesture locationInView:gesture.view];
// Create circle
UIView *cercleRouge = [[UIView alloc] initWithFrame:CGRectMake(point.x-(86/2), point.y-(86/2), 86, 86)];
cercleRouge.layer.borderColor = [[UIColor redColor] CGColor];
cercleRouge.layer.borderWidth = 4;
cercleRouge.layer.cornerRadius = cercleRouge.frame.size.height/2;
[gesture.view addSubview:cercleRouge];
}
Thank you in advance.

Double line in Canvas DBSignatureView

I'm implementing a digital signature in my application using Objective c, but when I tap the screen and drag the finger, the line is cut in two.
This is the code:
UIScrollView *contenido = [[UIScrollView alloc] init];
contenido.bounces = NO;
DBSignatureView *vistaFirma = [[DBSignatureView alloc] initWithFrame:CGRectMake(0, y, (margen-5) , tamCelda=tamCanvas)];
[
[![enter image description here][1]][1]vistaFirma addGestureRecognizer:gestureRecognizer];
vistaFirma.userInteractionEnabled = NO;
vistaFirma.layer.borderColor = [UIColor colorWithWhite:1.0f alpha:1.0f].CGColor;
vistaFirma.layer.borderWidth = 1.0f;
[contenido insertSubview:vistaFirma atIndex:contenido.subviews.count-(contenido.subviews.count > 1 ? 1 : 0)];
Which property should I implement?

animation not works in the non-initial UIViewController

I have a UIView called loadingView shows some UIActivityIndicatorView-like animation. There are two UIViewControllers that all have such UIView.
The initial UIViewController's code:
- (void)viewDidLoad {
self.loadingView = [[LoadingView alloc] initWithFrame:CGRectMake(10, 1, 120, 120)];
[self.view addSubview:self.loadingView];
}
Also it has a button to present the second UIViewController:
- (void)buttonPressed {
SecondViewController *sVC = [[SecondViewController alloc] init];
[self presentViewController:sVC animated:YES completion:nil];
}
The second ViewController's viewDidLoad method code:
- (void)viewDidLoad {
self.loadingView = [[LoadingView alloc] initWithFrame:CGRectMake(10, 1, 120, 120)];
[self.view addSubview:self.loadingView];
}
As you can see, the two UIViewControllers has the same viewDidLoad method code.
The loadingView works well in the initial UIViewController.
But in the second UIViewController, the loadingView only displays the black frame( I set the background colour to black).
Here is my loadingView implement code:
#define NUMBER_OF_DOT 15
#define DURATION 1.5
- (id)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self) {
self.replicatorLayer = [[CAReplicatorLayer alloc] init];
self.replicatorLayer.frame = frame;
self.replicatorLayer.cornerRadius = 10.0;
self.replicatorLayer.backgroundColor = [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.86].CGColor;
self.replicatorLayer.position = self.center;
self.replicatorLayer.instanceDelay = DURATION/NUMBER_OF_DOT;
[self.layer addSublayer:self.replicatorLayer];
float size = frame.size.width*14/200;
self.dot = [[CALayer alloc] init];
self.dot.bounds = CGRectMake(0, 0, size, size);
self.dot.position = CGPointMake(frame.size.width/2, frame.size.height/5);
self.dot.backgroundColor = [UIColor colorWithWhite:0.8 alpha:1.0].CGColor;
self.dot.borderColor = [UIColor whiteColor].CGColor;
self.dot.borderWidth = 1.0;
self.dot.cornerRadius = 1.5;
self.dot.transform = CATransform3DMakeScale(0.01, 0.01, 0.01);
[self.replicatorLayer addSublayer:self.dot];
self.replicatorLayer.instanceCount = NUMBER_OF_DOT;
float angle = 2*M_PI/NUMBER_OF_DOT;
self.replicatorLayer.instanceTransform = CATransform3DMakeRotation(angle, 0.0, 0.0, 0.1);
self.shrink = [[CABasicAnimation alloc] init];
self.shrink.keyPath = #"transform.scale";
self.shrink.fromValue = [NSNumber numberWithFloat:1.0];
self.shrink.toValue = [NSNumber numberWithFloat:0.1];
self.shrink.duration = DURATION;
self.shrink.repeatCount = INFINITY;
[self.dot addAnimation:self.shrink forKey:nil];
}
return self;
}
-(void)viewDidAppear:(BOOL)animated
{
self.loadingView = [[LoadingView alloc] initWithFrame:CGRectMake(10, 1, 120, 120)];
[self.view addSubview:self.loadingView];
}
Put this code in viewDidAppear of SecondViewController so it works in present mode as well.

iOS UIImagePickerController, set frame

I'm trying to accomplish the following result:
Set the frame of my UIImagePickerController to, lets say 200 x 200,
Set my frame at the bottom-right corner (just like Facetime/Skype does)
and show the front/rear (doesn't matter) camera stream.
Here's my code, for some reason, setFrame is not working!
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.view.frame = CGRectMake(600, 400, 200, 200); // NOT WORKING !!!
self.picker.toolbarHidden = YES;
self.picker.wantsFullScreenLayout = NO;
self.picker.delegate = delegate;
[self presentViewController:self.picker animated:YES completion:nil];
I've looked at similar SO topics but they all talk about how to
set a view on top of the UIImagePickerController, not my problem at all.
I've tried adding self.picker to a custom UIView sized 200 x 200 but still
no success.
What am i doing wrong here?
Thanks
You need to use the cameraViewTransform property of UIImagePicker to adjust its camera frame. This property accept any CGAffineTransform you made (e.g. scaling, rotating, inverting, translating, etc).
For example, if you want to move the camera view down by 50 points and scale the camera view 1.2x its original size, this is how you'll do it:
CGAffineTransform transform = CGAffineTransformMakeTranslation(0.0f, 50.0f);
transform = CGAffineTransformScale(transform, 1.2f, 1.2f);
imagePicker.cameraViewTransform = transform;
Swift 5:
var transform = CGAffineTransform(translationX: 0.0, y: 50.0)
transform = CGAffineTransform(scaleX: 2.0, y: 2.0)
imagePicker.cameraViewTransform = transform
From UIViewController reference link
presentViewController:animated:completion:
Discussion
On iPhone and iPod touch, the presented view is always full screen
If you want to embed image picker, you should manually add its view to one of your other views.
like this
[self.view addSubview:self.imagePickerController.view];
I experimented with the code from my last post, and commented out the final scale transform ((the one which makes it full size) and I ended up with a lovely miniature camera imagePicker floating in the middle of my screen, so it definitely does work! The exact code I used, including the zoom/fade-in transition, is -
UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];
imagePickerController.delegate = self;
imagePickerController.mediaTypes = [NSArray arrayWithObjects:(NSString *)kUTTypeImage, nil];
imagePickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
imagePickerController.cameraCaptureMode = UIImagePickerControllerCameraCaptureModePhoto;
UIView *controllerView = imagePickerController.view;
controllerView.alpha = 0.0;
controllerView.transform = CGAffineTransformMakeScale(0.5, 0.5);
[[[[UIApplication sharedApplication] delegate] window] addSubview:controllerView];
[UIView animateWithDuration:0.3
delay:0.0
options:UIViewAnimationOptionCurveLinear
animations:^{
controllerView.alpha = 1.0;
}
completion:nil
];
[imagePickerController release];

UIImagePickerController and a small custom preview

I want to use an UIImagePickerController non-modally, with a small square preview. However, I get a big black bar at the bottom of the preview, which I can't get rid of (see the screenshot). Why is it there, and how can I get rid of it?
Code:
- (void)viewDidLoad
{
[super viewDidLoad];
_imagePickerVC = [[UIImagePickerController alloc] init];
_imagePickerVC.sourceType = UIImagePickerControllerSourceTypeCamera;
_imagePickerVC.mediaTypes = #[ (NSString *)kUTTypeImage ];
_imagePickerVC.wantsFullScreenLayout = NO;
_imagePickerVC.delegate = (id)self;
_imagePickerVC.navigationBarHidden = YES;
_imagePickerVC.allowsEditing = NO;
_imagePickerVC.showsCameraControls = NO;
_imagePickerVC.cameraDevice = UIImagePickerControllerCameraDeviceFront;
CGRect previewFrame = CGRectMake(0, 0, 150, 150);
[_imagePickerVC.view setFrame:previewFrame];
_imagePickerVC.view.autoresizesSubviews = YES;
[self.view addSubview:_imagePickerVC.view];
[_imagePickerVC viewWillAppear:YES];
[_imagePickerVC viewDidAppear:YES];
}
This is a misuse of UIImagePickerController. To make your own image-capture interface, simply use AVFoundation.

Resources