UIPanGestureRecognizer distance - iphone

Is it possible to change the distance of the UIPanGestureRecognizer before it will trigger?, the current implementation seems to have a distance margin of 5-10pixels before it is triggered, I would like to lower it if possible.
The reason is I use the UIPanGestureRecognizer in combination with the UIRotationGestureRecognizer to change the rotation of a object, with UIPanGestureRecognizer because of the distance margin it will not rotate right away and therefore the first rotation update will not be smooth (because it will go from 0 to something like 5degrees)

Nope. UIPanGestureRecognizer does not have any extra settings available on it. You could, however, write a custom gesture recognizer to do this.

Related

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

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.

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 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.

Play & animate with UIButton?

I am doing some RnD work, looking forward for experts suggestion:
I have to create a custom Button with any defined background image. So that user can throw that button in any direction with smooth way, under which total covered distance is directly proportional to pressure applied on UIButton to throw it.
Can any one guide me so that i can cover this task ?
A good start would be to attach a UIPanGestureRecognizer to your button (or view or whatever), then use velocityInView:. From UIPanGestureRecognizer.h:
// velocity of the pan in pixels/second in the coordinate system of the specified view
- (CGPoint)velocityInView:(UIView *)view;
Using the velocity (possibly in conjunction with translationInView:) you can then move your button according to the speed and velocity of the gesture.

How can i rotate an arrow image by touch on that image?

I am working on a project where i need to rotate an image by touching it.
It can be rotate faster or slower depending on how the user touches it.
Can you show me some tutorials or how this can be done?
Place your image within a UIImageView, then either subclass that view and replace touchesBegan:withEvent: or set a delegate for it and implement the same method as a delegate method. This will give you the ability to respond to touch events (the beginning of a touch, in this case, although you can do the same for ending a touch or moving of the finger).
Within this touch handling method, you can implement something similar to what I describe here in order to perform a Core-Animation-enabled rotation of your UIImageView at a given speed. To alter the speed, change the duration property on the animation I provide. As I suggest there, you may want to look into a CAKeyframeAnimation to do a smoother animation with acceleration and deceleration at the beginning and end.
An easier way is to set up an NStimer and rotate the transform everytime it fires.
I've some sample code here that coincidentally does something similar:
http://github.com/kailoa/touchsamplecode/tree/master
Using Cocos2d, you can't have 'touch enabled' sprites, 'isTouchEnabled' is at the Layer level. You'll have to receive the touch at the layer level, then check the location of the touch against the location of the touchable sprite. The CGRect* functions include a 'rect contains point' which you can pass the touch location to, with the sprite's rect to see if it was 'touched', and which point you could then say [sprite runAction:[Rotate ....]]