Finger Swipe On iPad Screen - objective-c

How do i implement and code for recognizing swipes across the screen, and also making it so that if it swipes on a uiimageview then things happen, // code, how can i do this? THanks

Use UISwipeGestureRecognizer. Something like this to detect a swipe on imageView:
UISwipeGestureRecognizer *swipe = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:#selector(imageSwiped:)];
swipe.direction = UISwipeGestureRecognizerDirectionRight;
[imageView addGestureRecognizer:swipe];
[swipe release];
Then define a method - (void)imageSwiped:(UISwipeGestureRecognizer *)sender and react to the swipe there.

I suggest you use a UISwipeGestureRecongizer for it, unless you have a very specific gesture to recongize.
Try reading out : Event Handling Guide for iOS from Apple.

Related

Detect swipe down and close View with animation Objective C

I have a search button that onClick opens an UIView that covers most of the screen (It's like an UIAlertView). The UIView has as first element an UIImageView 2 UITextView and a close UIButton, what I want to add now is a gesture recognizer that works like this:
When the user drags the UIImageView down it also drags the UIView and it close it.
I tried with the following code in order to detect the Swipe gesture:
UISwipeGestureRecognizer *swipeGesture = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:#selector(swipeToDoMethod)];
[swipeGesture setDirection:UISwipeGestureRecognizerDirectionDown];
[[self popupImage] addGestureRecognizer: swipeGesture];
But I don't know how to proceed after this, can someone point me to the right direction in order to reproduce the effect I want?
missing delegate:
....
[swipeGesture setDirection:UISwipeGestureRecognizerDirectionDown];
swipeGesture.delegate=self;
....

UIImageView, tap and recognition

I have an UIImageViews with userInteractionEnabled, and i want to know with image i currently tap. What i should do to know that? I have a poster wall and class for that ThumbPosterModel there i have all poster information with i want to pass through.
So my code is:
for (ThumbPosterModel *tPoster in _thumbsPosterStack) {
UIImageView *imageView = [[UIImageView alloc] initWithImage:tPoster.thumb];
imageView.userInteractionEnabled = YES;
imageView.frame = CGRectMake(i, imageView.frame.origin.y, imageView.frame.size.width, imageView.frame.size.height);
[_posterWallScrollView addSubview:imageView];
UITapGestureRecognizer *tap =
[[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(imageTapped:)];
[imageView addGestureRecognizer:tap];
}
And then i have:
-(IBAction)imageTapped:(id)sender {
//something do here, but know i don't know what.
}
Should i subclass UIImageView that should contains all ThumbPosterModel params? I don't think it is good idea, but i can't figure any other solution.
Ok this is very simple just add tag proprty of each image with appropriate and distinct value other then 0 and use that proprty to identify the image :)
Happy Coding :)
When the gesture recognizer is fired the sender in the action is the recognizer, so you can get the UIView it is attached to by calling [sender view];
So you could write a method which searched the thumbs poster stack and found the poster with the matching thumb, but it would probably be easier to create a UIImageView subclass which contains a reference to the poster. So when you get the view just do
PosterImageView *selectedPosterView = (PosterImageView *) [sender view];
ThumbPosterModel *selectedModel = selectedPosterView.model;
Set a tag to your each imageView.
Each for loop iteration add your image view to a NSMutableArray (arrayRef).
Accessing the tag of image view when you tap the image view(tagImage) .
then
UIIMageView *imageViewR=[arrayRef objectAtIndex:tagImage-1];
The imageViewR is the tap imageView

Double-tap to zoom in PDF UIScrollView?

I have an "PDF Viewer" in my application. I use the CGPDFDocumentRef and CGPDFPageRef to show the PDF. To zoom in the PDF I use a UIScrollView.
I am already able to pinch-zoom in the UIScrollView but I also want to be able to double-tap to zoom.
Double tap with one finger takes you to different levels in the PDF until you hit the maximumZoomLevel and then be able to double-tap with two fingers to the minimumZoomLevel.
I haven't been able to find a solution on the Internet that shows you this in particular so I'm asking here. How could I accomplish this?
In viewDidLoad:
UITapGestureRecognizer *doubleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(handleDoubleTap:)];
[doubleTap setNumberOfTapsRequired:2];
[self.scrollView addGestureRecognizer:doubleTap];
[doubleTap release];
Method:
- (void)handleDoubleTap:(UIGestureRecognizer *)gestureRecognizer
{
if(self.scrollView.zoomScale > self.scrollView.minimumZoomScale)
[self.scrollView setZoomScale:self.scrollView.minimumZoomScale animated:YES];
else
[self.scrollView setZoomScale:self.scrollView.maximumZoomScale animated:YES];
}
I think that you can use UITapGestureRecognizer with numberOfTapsRequired property after that in handle method (which you specify when alloc/init the recognizer) and use to use – zoomToRect:animated: or – setZoomScale:animated: on the view to zoom.
Edit: keep track on current zoom level to reverse the effect.

I want to draw a focus indicator on camera view

I made an application using the camera.
I didn't use the default camera toolbar.
So I add a toolbar on camera overlay view.
I want to draw tap to focus indicator
So I used UITapGestureRecognizer.
Here is the code
UITapGestureRecognizer *focusRect = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(drawFocusRect:)];
focusRect.numberOfTapsRequired = 1;
focusRect.numberOfTouchesRequired = 1;
[cameraPicker.view addGestureRecognizer:focusRect];
[focusRect release];
In the drawFocusRect method
NSLog(#"tapped");
But it dosen't work.
I changed the value of numberOfTouchedRequired, 2;
And it works.
I think that it doen't work when only single-tap
So, how can I implement this single tapping gesture processing method?
I think camera view's focus view at top of all view.
And I think it has single tap action.
So If you want do this, you should read AVCamera demo in WWDC2010.

Touch event of a picture without using UIButton

Is it possible to register a touch of a picture without using UIButton? And if it is, how can i do this?
I can just think of changing the background of a button in the code, and then use IBAction to detect the touch.
Btw, sorry for my english.
Sure. You can put a UITapGestureRecognizer on a UIImageView (remember to set the image view's userInteractionEnabled property to YES):
// assumes "myImageView" is your UIImageView that has user interaction enabled
UITapGestureRecognizer * tap = [[[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(tap:)] autorelease];
[myImageView addGestureRecognizer:tap];
later in your controller...
- (void)tap:(UITapGestureRecognizer *)recognizer
{
// whatever you want
}
However, you can set up a UIButton to basically be a dumb image. Just set the background image for the normal state, disable all the adjusting on highlighting and touches, and you should have exactly what you're thinking of.
If I've misunderstood what you're getting at, feel free to clarify.