Custom multiple gesture on a view - ios

I created two custom gesture recognizer.
PinGestureRecognizer. this gesture is using for drag the view in horizontal direction.
TagGestureRecognizer. this gesture is using for increase the height of the view till user drag the view in vertically.
Now, i want to fail one gesture if another gesture got recognized.
Example:
if user drag the view horizontally in >=10 pixel need to recognized PinGestureRecognizer and fail TapGestureRecognizer and vice versa.
How can i achieve the functionality.
I know iOS7 provide the methods like
shouldBeRequiredToFailByGestureRecognizer:
shouldRequireFailureOfGestureRecognizer:
If its equal to my problem or not i was not able to understand. if its correct means kindly suggest me to get same functionality in iOS4 and above.
Thanks in advance....

Use the gestureRecognizerShouldBegin delegate method for the PinGestureRecognizer, for example:
// To handle not scrolling vertically
- (BOOL)gestureRecognizerShouldBegin:(UIPanGestureRecognizer *)panGestureRecognizer {
CGPoint translation = [panGestureRecognizer translationInView:myView];
return fabs(translation.y) < fabs(translation.x);
}

Related

Objective C change pinch gesture view

I'm stuck with a problem with pinch gesture. So I have a pinch gesture on an UIImageView which is itself in a collectionView, and when the user starts zooming, I add new, separates ViewController to control the zoom and pan gestures on the image, so I add my UIImageView to the new ViewController's view. The problem is, when I change my UIImageView hierarchy, the pinch gesture attached to it stops working, so the user has to take off his fingers and start pinch again in order to zoom the image. So basically, I am searching solutions to one off these:
1. Make pinch gesture work right when changing gesture.view hierarchy
OR
2. Make pinch gesture work right when changing gesture.view. So another way is to add a new view to the new ViewController and attach gesture to that view. But it still resets the gesture touches and you need to start it again.
If anyone has any suggestions, please help. Thanks a lot.
Ok, I found the answer. You just need to set userinteraction of vc's view to NO. Works like a charm.

iOS: How do I allow scrolling only when the user drags the scrollbar?

I have been trying to create a scrollable view using UIScrollView. I want this view to be a scratchpad where I can do rough work with touch gestures.
But, doing a drag gesture makes the UIScrollView move the page.
This is why I want to disable scrolling on gesture and enable scrolling only when I drag the scroll bars on the screen.
I have tried Googling, but haven't found any result so far.
It would be great if you could guide me to a solution or help me with some pointers.
Not sure you can or that it would be usable.
How about enabling scrolling only with 2 fingers? By setting the scroll view pan gesture minimumNumberOfTouches To 2.
Otherwise, think about acting as the delegate of the scroll view pan gesture, specifically for gestureRecognizer:shouldReceiveTouch: so that you can examine the touch position and only allow the gesture to start of significantly close to the edge of the view.
I world recommend using this library: https://github.com/BasheerSience/BRScrollBar
1- Use instance method to add the scrollBar
2- in your UIViewController add these lines of code
// First intit by using the instance method
_brScrollBarController = [BRScrollBarController initForScrollView:self.scrollView
inPosition:kIntBRScrollBarPositionRight
delegate:self];
// show the scrollBar always, do not hide
_brScrollBarController.scrollBar.hideScrollBar = NO;
// disable scrolling for your scrollView
self.scrollView.scrollEnabled = NO;
3- now your scrollView will not respond to gestures, and you will use BRScrollView to scroll by dragging the bar
let me know if you have any questions

How to scroll UIScrollView only with two finger swipe?

I have a UIView in which I draw with a finger, it all goes fine and dandy, but I need this view to be scrollable. So I made a UIScrollView, and embedded my drawing view in it.
But here comes the problem, I can't draw anymore since every tap goes to UIScrollView and it intercepts them for scrolling purposes.
What I want to do, is to make UIScrollView only intercept two finger swipes and with single touches and swipes just draw regularly.
How do I do that?
I draw by using simpe touchesBegan, touchesMoved methods by using BezierPath, without gesture recognizers.
Check out answer https://stackoverflow.com/a/3173290/1492816 in Scrolling with two fingers with a UIScrollView
People report it as working for the kind of situation you are in.
I have tried this, as suggested in that answer, but to no avail. It says that method recognizePan: is not found. I changed it to nil, and scrolling works with two fingers only as intended, by drawing functionality is missing.
I feel like the touches are not getting to my view. What can be done?
UIPanGestureRecognizer *panGestureRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self.scrollView action:#selector(recognizePan:)];
panGestureRecognizer.maximumNumberOfTouches = 1;
[scrollView addGestureRecognizer:panGestureRecognizer];

How to implement multiple simultaneous custom gestures in IOS?

Hi! My problem is not how to implement multiple custom gesture but how to handle multiple Custom Gestures. I have added a pinch custom gesture on corner points of the view and one finger rotation gesture on the view. For pinch custom gesture on corner points, I've used SPUserResizableView and for one finger custom gesture, I've used KTOneFingerRotationGestureRecognizer. But only one gesture is working. How can I resolve this? I've even tried using SPUserResizableView and default rotation gesture and it's not working. What may be the issue? Thank You.
may this links can help you. Simultaneous gesture recognizers in Iphone SDK
https://stackoverflow.com/questions/3160489/handle-tap-gesture-with-an-argument-iphone-ipad
Check it out it's all about gestures ,you doesn't need to use KTOneFingerRotationGestureRecognizer and SPUserResizableView.
You don't really need to use SPUserResizableView to handle the pinch gesture in the corners. You could probably get away with transparent subviews created programmatically, with the pinch gesture recognizer added to them.

UIScrollview, Move down responder chain

I'll try and keep it simple.
I have a UIScrollview with around 10 images attached. I currently have it so that i can touch an image and drag it around on the scroll view.
I did this by creating the subclass UIImageview and implementing the touchesMoved etc. I can still scroll the view fine, but the problem comes when trying to drag an image too fast. It seems the program first checks if the view is being scrolled and then fires touchesMoved in the UIImage class.
Is there anyway I can switch this around so that the first check is if an image is touched, then if not pass the response onto the scrollview.
Any help would be great. Thanks.
The simplest way to do this would be use one finger to move an image, and two fingers to scroll the view.
If you're on iOS 5, this is super easy:
self.scrollView.panGestureRecognizer.minimumNumberOfTouches = 2;
If you want to support older versions of iOS, you have to do a little more work:
for (UIGestureRecognizer *gesture in self.scrollView.gestureRecognizers){
if ([gesture isKindOfClass:[UIPanGestureRecognizer class]]){
((UIPanGestureRecognizer *)gesture).minimumNumberOfTouches = 2;
}
}
If you want to use one-finger gestures for both, there are a few ways to do it. You could attach a UIPanGestureRecognizer to each image view. You might need to tell the scroll view's own UIPanGestureRecognizer to defer to the image view recognizers, using the requireGestureRecognizerToFail: message.
Another way would be to set the scroll view's UIPanGestureRecognizer's delegate to an object you create that implements the gestureRecognizer:shouldReceiveTouch: method. In that method, you can check whether the touch's view is one of your image views. If so, return NO to prevent the scroll view's pan gesture recognizer from activating.
Your question is a little confusing to me but I will assume that you have a UIScrollView with 10 UIImageViews inside it which you want to drag around.
My suggestion would be to use a gesture recognizer (UIPanGestureRecognizer) attached to every UIIImageView in order to implement the dragging behaviour. I find gesture recognizers to be a more solid approach on this kind of behavior.
If you don't know how to work with gesture recognizers, I can post a short code example to demonstrate how you can drag any type of UIView. Just ask in a comment and I will write it.

Resources