How to implement an angle detecting swipe gesture recognizer in SceneKit? - swift

What I basically want to do is allow a user to swipe on their screen in any forward facing direction to launch a projectile at a target in that direction. I did look over UISwipeGestureRecognizer but I wasn't able to figure out how to implement one that allows swiping in any angle while also allowing me to determine the angle to launch the projectile.

See the "Methods for Subclasses" section of the UIGestureRecognizer class doc. You should be able to override touchesBegan/Moved/Ended in your UISwipeGestureRecognizer subclass, and determine the angle to launch.

Related

UIPanGestureRecognizer translationInView vs locationInView

I'm taking the first steps in Swift
What is the best method to move UIView along X coordinate for UIPanGestureRecognizer?
Usually Programmers use translationInView for pan gesture
But I suppose the locationInView is more convenient for this purpose
translationInView provides the change in coordinates that the view has moved within the view it is contained in. That is given in the form of a CGPoint.
If you drag it to the left, it might provide the coordinates:
(-20.0, 0)
locationInView provides the location of the view in the form of a CGPoint.
If you drag it to the left and print the locationInView throughout the gesture, you will see a slur of logs with changing coordinates with the final one being its current resting place.
To move a UIView with the touch's location, you would want to set the frame property of the UIView to the gesture's locationInView in the gesture's delegate method.
A pan gesture is composed from individual touches on the screen, locationInView gives you the current position of the touch on the screen, translationInView gives you the movement relative to the previous touches.
When panning, you are usually interested more in the movement (e.g. when scrolling, you don't want to know where the scroll began and where it ended) and not in the current position. If you are using the pan recognizer for example for drag and drop, then the location will interest you in the final position (you want to know where to drop).

How can I Know the force of a swipe Gesture Recognizers?

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

How to set more directions for UISwipeGestureRecognizer?

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.

How do I detect a swiping / flicking gesture?

I want to allow the user to flick a ball that is on screen. The user would tap on the ball and then flick, the velocity / speed of the flick would then dictate initial velocity.
I took a look at UISwipeGestureRecognizer but it seems like that is more targeted at navigation than flicking.
How do I go about implementing this?
I am using Cocos2d and Box2d.
Have you considered UIPanGestureRecognizer? You can get velocity data from that ([panGesture velocityInView:]), and distinguish the initial velocity of the 'swipe' using the state property on the gesture recognizer.
Or is that not sufficient?

UIView Rotation using CGAffineTransform

I want to rotate an UIView using CGAffineTransform and I'm able to rotate View using CGAffineTransform.
But I want to rotate UIView smoothly on finger touch based on swipe gestures.
So like right swipe, left swipe I was able to detect swipe but when I swipe from down to right or from down to left, I'm not able to detect swipe gesture of these types...
Sanjay these are the only allowable gestures that a iPhone supports
http://developer.apple.com/library/ios/#DOCUMENTATION/UIKit/Reference/UISwipeGestureRecognizer_Class/Reference/Reference.html#//apple_ref/occ/instp/UISwipeGestureRecognizer/direction
so I think you are trying to recognize a diagonal swipe gesture and the its not working.
and also there is a minimum numberOfTouchesRequired required for swipe gesture.
http://developer.apple.com/library/ios/#DOCUMENTATION/UIKit/Reference/UISwipeGestureRecognizer_Class/Reference/Reference.html#//apple_ref/occ/cl/UISwipeGestureRecognizer
And if you want to rotate a UIView object than I think you will find the code in this link
rotating a view on touch
Hope this helps.