I want to move a image to the right or to the left with the swipe gesture recognizer, i´m already moving the image using the CCMoveTo function, but I don´t know how move the image faster or slower depends of the force of the swipe.
If the user make a strong swipe the image should move faster than if the user make a soft swipe.
Anyone have any advice?
A UISwipeGestureRecognizer is a one shot thing. It fires when the device detects the gesture and is done after that.
If you want more information about the movement of the finger you should check UIPanGestureRecognizer.
That's what the property velocity in the UIPanGestureRecognizer is for. You can see an example of how to use it in class 08 (I think) of cs193p by Paul Hegarty. Here's the link to download it from iTunes U
Related
UISwipeGestureRecognizer has four directions that I can set: up, down, right, left.
but as I tried to set, the direction of a swipe seems need to be quite precise. I mean, for example, if I set a UISwipeGestureRecognizer with toUp direction, and if I swipe my finger not that precise toUp, say 45 degree in the middle of up and right, the UISwipeGestureRecognizer can't get it.
But I noticed that for UIScrollView, it is not the case.
So How can I give more directions for UISwipeGestureRecognizer or how can I make the direction check more relax?
Thanks
It's probably best to use Apple's swipe gesture to be consistent with their Apps. You could try defining your own by subclassing the UISwipeGestureRecognizer, or creating your own class using the older UITouchesBegan, UITouchesEnded, etc methods.
Hi all:
I want to write a gesture recognizer on the iphone, that I cold use two finger to drag the view. Just like we use two finger on the MacBook Pro's touch pad.
If the view's size is larger than the window's size of the device, I could use two finger to drag the view. is there any good way to solve it ?
(Thanks enamrik and Naveen Thunga. I achieved my goal just now, but there is a new question that how could I know the UILongPressGestureRecognizer is over. I want call a method and set some value when my finger leaves the screen of my iphone.)
The UILongPressGestureRecognizer class has a numberOfTouchesRequired property you might find useful
Use uigesturerecognizer's properties and enable View's multitouch property. See some sample on UIGestureRecognizer that may help you.
I'm trying to have a sort of gesture that will seamlessly switch between a group of images this part I have sorted. The part that is catching me up is the gesture to do so and how I might introduce acceleration.
Basically the user would swipe as normal and after the swipe is registered it would change the image displayed and the faster once swiped the faster the image would change ideally it would then keep that speed until the users finger was lifted leaving the possibility to just scroll repeatedly through the images.
Any direction someone could give me would be great.
Thanks.
Assuming you would be using a UIScrollView for this, setting the scrollView.decelerationRate property would allow you to manipulate the deceleration rate/scroll speed. To calculate the "swipe speed", take a look here: Detecting Special touch on the iphone for some pointers.
What I would like to do is to detect a swipe gesture followed by a pan gesture as part of the same touch sequence. So the user first swipes an object to carry out an action, then, while keeping their finger on the screen, moves up/down to propagate the action to surrounding objects.
I have a swipe gesture recognizer and a pan gesture recognizer.
It seems to me that the ideal way to make them behave the way I want is to do this:
[myPanGestureRecognizer requireGestureRecognizerToSucceed:mySwipeGestureRecognizer];
But although I was sure that I hadn't just imagined requireGestureRecognizerToSucceed:, it seems I have.
Is there a way to achieve what I want without subclassing UIGestureRecognizer?
You can do this by setting both the swipe and the pan to recognize simultaneously, and subclassing the pan so that it does actually mark itself as recognized until the swipe has been recognized.
I want to switch between a couple views with a flick gesture using two fingers. If anyone can tell me what I need to do please help.
Without actually writing the code for you, here's what you'll need to do to track a multi-finger swipe:
First, set your view's multipleTouchEnabled property to YES so that you'll be able to track multiple touches.
In touchesBegan, store the each touches' locationInView property (this is a CGPoint).
Define a "swipe window" that limits the amount of off-axis motion you'll accept and still consider the gesture a swipe. If, for instance, you're looking to track horizontal stripes, perhaps you'd want a "swipe window" of 12x6 -- that is, if your touches move at least 12 horizontal pixels while moving fewer than 6 vertical pixels, you'll consider it a swipe.
In touchesMoved, compare the current location of the touches with the stored starting locations from step 2. If they're still in the "swipe window," do nothing. If one or both of the fingers has moved outside of its "swipe window," then cancel the swipe checking. If they've both met the requirements for a swipe, fire whatever method you want to have called when you've detected a multi-finger swipe.
In 'touchesEnded', stop tracking the swipe, since if the touches have ended but you still haven't fired the swipe method from #4, then they must not have constituted a swipe.
Hope this helps.