About UIRotationGestureRecognizer - iphone

Can I get the middle point coordinate of the UIRotationGestureRecognizer's two fingers? Or the location of each finger? Thank you.

You can get either.
The docs for UIRotationGestureRecognizer show the properties velocity and rotation.
This is specific to the rotation.
But you can use these methods from the UIGestureRecognizer...
Getting the Touches and Location of a Gesture
– locationInView:
– locationOfTouch:inView:
– numberOfTouches
To get the touches and locations.
From these you can easily calculate the mid point.

UIRotationGestureRecognizer extends UIGestureRecognizer which has the two methods: numberOfTouches and locationOfTouch:inView:. Use these to get the location of each finger. From there you can calculate a center.

Related

iOS how to keep current location center all the time

My map shows current location with blue dot..
Of course, when I move, blue dot moves.. I just want to keep blue dot center of the map all the time, making map's moving instead like Google map navigator..
I searched a lot but couldn't find the way...
In your map view delegate, do this:
- (void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation
{
[mapView setCenterCoordinate:userLocation.location.coordinate animated:YES];
}
Try using mapView.userTrackingMode = MKUserTrackingModeFollow;, you'll get smoother panning than using the location manager manually.
In addition note that there is a ready-made button for managing the various tracking states:
MKUserTrackingBarButtonItem.
The easiest way would be to create a new UIView on top of your map's view with a blue dot and only move the map's view.

Current Touch location

How does one get the current touch location from a GestureRecognizer?
I need to get the current touch location when the touch has begun as well as when the touch has ended.
What property is used to get this location?
Thanks
In your gesture recognizer handler:
CGPoint location = [gestureRecognizer locationInView:gestureRecognizer.view];
you could specify a different view, if you need it.

Using multi-touch on iPhone & iPad

How do I get the co-ordinates of 2 touches on an iPhone? (both co-odiantes)??? This is killing me... any sample code would be great. Thanks.
If you are using touchesBegan:withEvent: and its siblings, you will be passed an NSSet object containing all the touches. You can get an NSArray using allObjects method on the set. You can retrieve individual UITouch objects using objectAtIndex: method. The UITouch object can give you coordinates based on any view's frame through the method locationInView:. The call will be on the lines of CGPoint point = [touch locationInView:self.view];. Do this for all the touches in the array.
If you are using gesture recognizers, the gesture recognizer object has a method numberOfTouches that gives you the number of touches and you can retrieve the location of each touch using locationOfTouch:inView:.
check touches began, touches moved, touches ended, and touches cancelled. here is the link for this UIResponder class reference

Stealing two-finger pan from mkmapview

I've placed a UIview above an MKMapView with the intention of stealing the two-finger pan from the map view when I am tracking a user's location. If you notice Google maps app does this on the phone as well.
But I'm at a loss as to how to do it. I want to be able to enable it and disable it at will depending on whether the location is being tracked or not. All other gestures and touches should be passed onto the mapview
thanks in advance.
Assuming you're going for OS 4 and above, the easy way is NOT to use a UIView, but instead to add a gesture-recognizer directly onto the mapview, e.g.:
UIPanGestureRecognizer* gest = [[UIPanGestureRecognizer alloc] initWithTarget:self action:#selector(handlePanGesture:)];
[mapView addGestureRecognizer:gest];
...and then all swipe gestures (in that case) would get passed to [self handlePanGesture:(UIPanGestureRecognizer*) x];
If you look in the docs around gesture recognizers, there's a wide variety of options, and you can add them to a pretty fine-level of granularity (tap vs swipe, how many fingers used, etc)

Always animate UIView to user's tap location

I have a UIView that I want to animate to the position where the user's finger currently is.
So, when the touch begins, it has to animate to the tap location.
When the touch moves, it has to adjust its destination to the new location.
When the touch ends, it has to finish the animation to the last tap location.
I tried several things but none worked out. I tried creating a new animation with beginsFromCurrentState in touchesMoved, but that didn't work too.
It seems you're complicating this a little bit. If you are implementing touchesMoved, you are wanting a drag. If you are more interested in a tap, then touchesEnded is where you want to implement this. Either way, you just need to get the location in view and update your UIView's center based upon that location. If you wrap the change to the center value in a UIView animation block, it will animate to the position as it updates.
If you are using iOS 3.2 or later, you can use gesture recognizers which makes this pretty trivial:
// In viewDidLoad or some such
UITapGestureRecognizer *tapRecognizer = [[UITapGestureRecognizer alloc]
initWithTarget:self action:#selector(viewWasTapped:)];
[[self view] addGestureRecognizer:tapRecognizer];
Then declare your action selector:
- (void)viewWasTapped:(UITapGestureRecognizer*)recognizer
{
CGPoint location = [recognizer locationInView:[self view]];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1.0f]; // take a second to animate
[viewToMove setCenter:location];
[UIView commitAnimations];
}
This will animate the view from one location to another. This is referred to as implicit animation. Using Core Animation classes such CAKeyframeAnimation or CABasciAnimation would be explicit animation.
Need a few more details for this.. But are you sure you are using touchesBegan, touchesMoved and touchesEnded from the appropriate view (ie not the view you want to move)? Also make sure the userInteractionEnabled = YES. Try logging the touches from touchesBegan to make sure you are receiving the touches.
Or you might want to just check out Apples MoveMe sample code at https://developer.apple.com/library/ios/#samplecode/MoveMe/Introduction/Intro.html where they have solved all those problems for you.