Detect swipe down and close View with animation Objective C - 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;
....

Related

ScrollView is eating Swipe Gesture Recognizer

i have a details view controller with a scrollview on it. And i have load UILabel, UIImageView on top of UIScrollView. The scrollview is set to scroll vertically only. and the view need to be able to recognize swipe left and right to navigate to next/previous page by adding
self.leftGestureRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:#selector(swipeRecognizer:)];
[self.leftGestureRecognizer setDirection:UISwipeGestureRecognizerDirectionLeft];
[self.view addGestureRecognizer:self.leftGestureRecognizer];
So when i swipe within UILabel, it is working. If i swipe start from UIScrollView, it is not working. I guess it is the UIScrollView conflict the swipe gesture.
In short, swipe gesture is only working on the subview but not UIScrollView .Does anyone have any idea on this?
UPDATE:
If i swipe start from scrollview first then end at UILabel, it won't recognize the swipe gesture. If i swipe within UILabel(start and end in the UILAbel) it is able to recognize.
Make sure that if the UIImage allows zooming, the swipe recognizer won't work, since it is trying to zoom. If this is the case, you will need to enable the zoom only in certain case. hope it helps.
Initialize the scroll view with scrolling disabled. Then you need to disable scrolling in the scroll view when the image is not zoomed in, and renabled it when it is zoomed in. This provides the expected behavior.
- (void)scrollViewDidZoom:(UIScrollView *)scrollView {
if (scrollView.zoomScale != 1.0) {
scrollView.scrollEnabled = YES;
} else {
scrollView.scrollEnabled = NO;
}
}
To enable zoom provide an image on a delegate.
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView {
return myImage;
}
Also add the gesture to instance of scrollview like this -
leftGestureRecognizer.delaysTouchesBegan = YES;
[myScrollView addGestureRecognizer:leftGestureRecognizer];
OR You can try the following -
[scrollView.panGestureRecognizer requireGestureRecognizerToFail: leftGestureRecognizer]

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.

Change Gesture Recogniser Position?

I have a gesture recogniser to detect a tap on a UIImageView, however I force a position change of the image when the orientation of the iPad changes but this causes the gesture recogniser to repositioned incorrectly. How can I resolve this?
EDIT:
strapTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(strapTap:)];
[(UITapGestureRecognizer *)strapTap setNumberOfTapsRequired:1];
strapTap.delegate = self;
[leatherButtonedStrap addGestureRecognizer:strapTap];
This above is how I setup the gesture, adding it to my UIImageView. However, something which might cause a stir is that I add the this view to my main view, remove it and then re-add it when the user presses a certain button. Hard for you to understand whats happening unless you saw the entire class, but let me know if this is enough to go on or not.
Make sure when you're calling locationInView: in strapTap: to send the leatherButtonedStrap as the parater:
CGPoint location = [recognizer locationInView:leatherButtonedStrap];
So that the location is relative to leatherButtonedStrap's coordinate system an not it's superview's.

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.

Finger Swipe On iPad Screen

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.