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];
Related
I'm using the following code to attempt to flip a UIView. It's a playing card. There's a container view, with two children, front and back. I've read in similar questions here that this should be the correct way to do it, but the actual flip itself is not being performed.
I'm intending for this to animate moving the card to the centre of the screen, and flip it from its back to front. The movement to centre is fine, but the flip never occurs.
If I change the View: argument to self, it flips the entire view controller, and if I leave it on the cardContainer, it does nothing at all.
Puzzled :(
UIView *cardContainer = [[UIView alloc] initWithFrame:CGRectMake(20, self.view.frame.size.height + 20, [Card size].width, [Card size].height)];
[self.view addSubview:cardContainer];
Card *card = _playerOneCards[_playerOneNextCardIndex];
card.frame = CGRectMake(0, 0, [Card size].width, [Card size].height);
card.delegate = self;
[cardContainer addSubview:card];
CardBack *back = [[CardBack alloc] initWithFrame:CGRectMake(0, 0, [Card size].width, [Card size].height)];
[cardContainer addSubview:back];
[UIView transitionWithView:cardContainer
duration:duration
options:UIViewAnimationOptionTransitionFlipFromLeft
animations:^{
back.alpha = 0.0f;
cardContainer.center = self.center;
}
completion:nil];
Try this. The container view has to be placed in the hierarchy before the animation starts.
//Add container views and subviews
[CATransaction flush];
[UIView transitionWithView:cardContainer
duration:duration
options:UIViewAnimationOptionTransitionFlipFromLeft
animations:^{
back.alpha = 0.0f;
cardContainer.center = self.center;
}
completion:nil];
You can also wrap your function up in a dispatch_after call.
For more information check : http://andrewmarinov.com/working-with-uiviews-transition-animations/
I am trying to add an overlay to image taken with imagePicker such as a frame, shown during snap taking. I was trying to use the following code:
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];
But this helps when changing the image picker skin. How can I add and process an overlay with the snapshot?
If you need to merge a picture taken with another UIImageView that contains an image, here's a useful snippet:
yourFile.h:
UIImage *combinedImage;
yourFile.m:
-(void)savePicture { // call this method from an IBAction button
// Crop a Combined Image from the taken picture
CGRect rect = [_imagePreview bounds];
UIGraphicsBeginImageContextWithOptions(rect.size,YES,0.0f);
// Render both images, the captured one from the camera and the UIImageView that is over that picture
[__myCapturedImage.layer renderInContext:UIGraphicsGetCurrentContext()];
[_overlayImageView.layer renderInContext:UIGraphicsGetCurrentContext()];
combinedImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
_myCapturedImage.image = combinedImage;
// Automatically Save the Image into Photo Album (if you want to do so)
UIImageWriteToSavedPhotosAlbum(combinedImage, nil, nil, nil);
}
Hope this helps!
PS: we have made a nice template that actually processes overlays images (which are frames around images) here: http://codecanyon.net/item/picshape-frame-image-editor-full-app-template/7852895?ref=fvimagination
Cheers!
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;
Just like Häagen-Dazs' App, I think it just add an animation before the photo iPhone is taking. I have checked UIImagePickerController and it didn't say how to add another picture or animation before the image. I just want to add some interesting things in front of the scene that I'm taking. Could anyone provide any tutorial? Thanks.
add you custom UIView with animation like this into ImagePickerView
_imagePickerCamera.sourceType = UIImagePickerControllerSourceTypeCamera;
_imagePickerCamera.delegate = self;
_imagePickerCamera.showsCameraControls = NO;
_imagePickerCamera.navigationBarHidden = YES;
_imagePickerCamera.toolbarHidden = YES;
_imagePickerCamera.wantsFullScreenLayout = YES;
//create an overlay view instance
OverlayView *overlay = [[OverlayView alloc]
initWithFrame:self.view.bounds];
//set our custom overlay view
_imagePickerCamera.cameraOverlayView = overlay;
overlay.captureButton.frame = CGRectMake(self.view.frame.size.width/2 - 30, self.view.frame.size.height - 60, 60, 60);
[overlay.captureButton addTarget:self action:#selector(captureImageWithButton:) forControlEvents:UIControlEventTouchUpInside];
[self performSelector:#selector(presentCameraView) withObject:nil afterDelay:0.0f];
You can add any overlay view you want using the cameraOverlayView property of the UIImagePickerController class.
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.