I'm trying to add UIPinchGestureRecognizer to UIImagePickerController to zoom in/out front camera but were not able to call method inside UIPinchGestureRecognizer (handlePinchWithGestureRecognizer). I didn't get any error but also didn't get any interaction.
Here is the code I'm using in viewDidAppear:
_imagePicker = [[UIImagePickerController alloc] init];
_imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
_imagePicker.cameraDevice = UIImagePickerControllerCameraDeviceFront;
_imagePicker.allowsEditing = YES;
_imagePicker.showsCameraControls = NO;
_imagePicker.navigationBarHidden = YES;
_imagePicker.view.userInteractionEnabled = YES;
_imagePicker.view.multipleTouchEnabled = YES;
_imagePicker.delegate = self;
UIPinchGestureRecognizer *pinchGestureRecognizer = pinchGestureRecognizer = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:#selector(handlePinchWithGestureRecognizer:)];
[_imagePicker.view addGestureRecognizer:pinchGestureRecognizer];
[self presentViewController:_imagePicker animated:NO completion:nil];
First of all I wouldn't add gesture recognizers to UIKit View Controllers' views that are not meant to be subclassed. You don't know for sure what's going on in there, and how your recognizer may interfere with the view's standard features.
Secondly, I tried to zoom the front camera on my iPhone and it's not possible to do so.
If you want to get video from the front camera and zoom it you will have to implement your own Controller that takes a video session from the front camera and do the transformations to do the zooming, etc.
Related
I have an AVPlayerViewController that will have some views on top of it (only when it's in fullscreen). The views have gesture recognizers on them (these work). The problem is that when a user taps on one of the views (they are invisible) the player doesn't also receive the touch... I need the player to show the player controls then..
This is how I add the views
_topHelperView = [[UIView alloc] init];
_topHelperView.backgroundColor = [UIColor purpleColor];
_middleHelperView = [[UIView alloc] init];
_middleHelperView.backgroundColor = [UIColor redColor];
[self setHelperFrames];
_topTapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(handleHelperTapGesture:)];
_topTapGestureRecognizer.delegate = self;
_topTapGestureRecognizer.cancelsTouchesInView = NO;
_middleTapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(handleHelperTapGesture:)];
_middleTapGestureRecognizer.cancelsTouchesInView = NO;
_middleTapGestureRecognizer.delegate = self;
I also implemented the delegate:
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch {
return YES;
}
// this enables you to handle multiple recognizers on single view
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer{
NSLog(#"should Handle simultaneously %# %#",gestureRecognizer,otherGestureRecognizer);
return YES;
}
This doesn't work .. the player doesn't show the controls when either view is tapped.. it only shows them when it's tapped directly ..
Any workaround for this?
Touch events stop when a view (actually a UIResponder) responds to them. So if you have a gesture recognizer attached to a view on top of your AVPlayerViewController, the gesture recognizer will catch the events and the AVPlayerViewController will not. This is by design.
Why not have your view send messages to the AVPlayerViewController in response to the user's gestures? AVPlayerViewController has a property showsPlaybackControls. Set that to YES if you want the player to show its controls.
Is there a way to play through a sequence of images using the Pinch Gesture tool in XCode? If so, how?
Any help will be greatly appreciated! :)
Dave.
this is the common solution , by adding pinchGesture in every imageView and this calls the callback delegate , when ever the gesture event starts.
for (int i = 0;i<=8;i++){
UIImageView *imageView = [[UIImageView alloc] init]
imageView.userInteractionEnabled = YES;
UIPinchGestureRecognizer *pinch = [[UIPinchGestureRecognizer alloc]
initWithTarget:self action:#selector(handlePinch:)];
pinch.delegate = self;
pinch.tag = self;
[imageView addGestureRecognizer:pinch];
}
- (void)handlePinch:(UIPinchGestureRecognizer *)pinchGestureRecognizer
{
//handle pinch...
}
I'd like to use the front and back camera at the same time in iOS developing:when I take one photo using back camera,after that the front camera could be opened and take another photo.By the way,this two photos are in the one picture:Vertical arrangement.
Is anybody has done this before?
Use UIImagePickerController to take the pictures, and use the cameraDevice property to determine which camera is in use.
For merging images I found an example via searching(recommend it in the future) merges multiple images into one image
Super simple this is the an easy way of doing it. Just replace my imagNamed with you images and the selector is the new methods that were created. This is used for a custom camera by removing showsCameraControls = NO;
#interface yourClassName () {
UIImagePickerController *picker; //this calls the video/photo screen
UIButton *cameraFront, *cameraBack //front and back buttons
}
//in your UIImagePickerController
picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
picker.mediaTypes = [[NSArray alloc] initWithObjects: (NSString *) kUTTypeMovie, nil];
picker.showsCameraControls = NO;
[cameraFront setBackgroundImage:[UIImage imageNamed:#"camera_switch_logo"] forState:UIControlStateNormal];
UITapGestureRecognizer *camerafront = [[UITapGestureRecognizer alloc]
initWithTarget:self action:#selector(deviceModeFront:)];
[cameraFront addGestureRecognizer:camerafront];
[cameraBack setBackgroundImage:[UIImage imageNamed:#"camera_switch_logo2"] forState:UIControlStateNormal];
UITapGestureRecognizer *cameraback = [[UITapGestureRecognizer alloc]
initWithTarget:self action:#selector(deviceModeBack:)];
[cameraBack addGestureRecognizer:cameraback];
cameraBack.hidden = true;
//These are the new methods created as the selector for when image is pressed
- (IBAction)deviceModeFront:(id)sender {
[picker setCameraDevice:UIImagePickerControllerCameraDeviceFront];
cameraFront.hidden = true;
cameraBack.hidden = false;
}
- (IBAction)deviceModeBack:(id)sender {
[picker setCameraDevice:UIImagePickerControllerCameraDeviceRear];
cameraFront.hidden = false;
cameraBack.hidden = true;
}
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'm using UITapGestureRecognizer
This is my code:
Home.m:
- (void)viewDidLoad {
[super viewDidLoad];
UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc]initWithTarget:self action:#selector(tapAnim:)];
[self.view addGestureRecognizer:tapGesture];
UIButton *buttontest = [[UIButton alloc] init];
buttontest.backgroundColor = [UIColor whiteColor];
buttontest.frame = CGRectMake(0, 80, 40, 40);
[buttontest addTarget:self action:#selector(test:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:buttontest];
[self.view bringSubviewToFront:buttontest];
}
- (void)test: (UIButton*)aButton {
// TakePhoto *mvc = [[TakePhoto alloc]initWithNibName:#"TakePhoto" bundle:Nil];
// [self.navigationController pushViewController:mvc animated:YES];
//
// [self.view removeFromSuperview];
if (self.companyController) {
self.companyController = nil;
}
self.companyController = [[TakePhoto alloc] initWithNibName:#"TakePhoto" bundle:nil];
UIView *viewSuper = [[IQAppDelegate shareInstance] currentVisibleController].view;
UIViewController *profile = self.companyController;
profile.view.frame = viewSuper.frame;
[viewSuper addSubview:profile.view];
profile.view.frame = CGRectMake(viewSuper.frame.origin.x, viewSuper.frame.size.height, profile.view.frame.size.width, profile.view.frame.size.height);
[UIView beginAnimations:nil context: nil];
[UIView setAnimationDuration:0.35];
profile.view.frame = CGRectMake(viewSuper.frame.origin.x, viewSuper.frame.origin.x, profile.view.frame.size.width, profile.view.frame.size.height);
[UIView commitAnimations];
}
}
- (void) tapAnim: (UITapGestureRecognizer*)gestureRecognizer {
// Show something
}
TakePhoto.m
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
picker.delegate = self;
picker.allowsEditing = NO;
[(UIViewController *)self.delegate presentModalViewController:picker animated:YES];
I add a view:Takephoto front of Home(i'm not use "push"), like this:
--->Home
--->Take photo (like a popUp show): it has 2 buttons "Choose photo from library" and "Close"
When i use function "Choose photo from gallery", i cant choose a photo and UITapGestureRecognizer is always show.
How to disable UITapGestureRecognizer when choose photo from gallery?
P/S:sorry about my english.
Gesture recognizers have the enabled property. Set this to NO to disable the gesture recognizer. To make this easier you should keep a reference to the tap gesture recognizer using an instance variable.
you can set tapGesture.enabled=NO before you choose photos.
I think you need to implement this below delegate method :-
- (BOOL)gestureRecognizer:
(UIGestureRecognizer *)gestureRecognizer
shouldReceiveTouch:(UITouch *)touch
When you look on the documentation it will return YES (by default) to allow the gesture recognizer to examine the touch object, NO to prevent the gesture recognizer from seeing this touch object. For more details follow this https://developer.apple.com/library/ios/DOCUMENTATION/UIKit/Reference/UIGestureRecognizerDelegate_Protocol/Reference/Reference.html#//apple_ref/occ/intfm/UIGestureRecognizerDelegate/gestureRecognizer:shouldReceiveTouch: