Using multi-touch on iPhone & iPad - iphone

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

Related

restart an uitouch

I've tried all morning, and start to think it's impossible.
So you have a touch in your screen, it entered the response chain and maybe did something. Then you moved it on the screen it called the touchesMoved: method (of the uiResponder associated with the touch) and maybe did other stuff.
At this point, is there anyway, that the touch continues to move in the screen, and when it enters some other uiView, the uiTouch gets reinitialized (I mean, call touchEnded, in the first uiView, then in the new uiView call touchesBegan, and then if continues movement call touchesMoved).
I've tried to resignFirstResponder and to manually call the methods, and I just can't.
I keep thinking that there should exist a really simple answer for this. Something like
UITouch *touch = [touches anyObject];
CGPoint location = [touch locationInView:self.superview];
if (!CGRectContainsPoint(self.frame, location)) {
[touch restart];
}
or
[[touch phase] restart];
(But anything in documentation ):
My recommendation would be to have the superview of all the views you want to transition through to receive the touches, then do a hit test on the subviews within the touchesMoved/Began/Ended methods (probably via CGRectContainsPoint(...)), and pass the touches along accordingly (calling the corresponding touchesBegan/Moved/Ended method on the subview).

How to determine x&y of last touch in multitouch scenario?

I'm new to this site and to iOS programming.
I am working on a percussion app. For this I want to know the x and y location of every finger that touches the screen. I thought this was straightforward, but multitouch is making things confusing for me.
Suppose the user has two fingers pressed on the screen and the user presses a third finger on the screen. How do I determine the location of this third finger?
My feeling is that I need to implement touchesBegan
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
To determine the x and y location I have to look at the touch that triggered this call to touchesBegan. But the touches are presented in an unordered set. If the third finger triggered this touchesBegan, then I have three touches in the NSSet. But since the set is unordered, how do I determine the touch that triggered this third call to touchesBegan? If I understand my documentation correctly it could be any of those three touches.
Many thanks in advance
Maybe you can add a simple counter property and increase its value in touchesBegan and decrease in touchesEnd.
Okay, it now turns out I have been mis-interpreting my test-data. If two fingers already touch the device when a third finger touches the device, only one UITouch object is part of the NSSet in the call to touchesBegan, and not three as I seemed to experience. This one UITouch represents the last fingertouch.
The only time when more than one UITouch object is passed to touchesBegan is when in fact multiple fingers begin to touch the device at the same time.
Since, in my case, I need to handle all new touches based on their location, I need to handle all UITouch objects in the NSSet.
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
for ( UITouch *touch in touches)
{
CGPoint location = [touch locationInView:self.view];
// Handle finger touch at given location
// ...
}
}

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.

iPhone - Passing touch event to MPMoviePlayerController

Is it possible to pass touch event (by coding) to MPMoviePlayerController?
I don't want to detect touch. Just pass touch event.
I want to generate an event and pass it to MPMoviePlayerController as if user touched the player. Something like user touched the player at location x=100 and y=100
(I can't give in depth details due to some restrictions).
Have you tried extending the MPMoviePlayerController and just making sure all the touch events are passed.
You can even do this reverse to make sure the player view is being touched by adding your player view as a subview and then overloading the touch events in your Controller. Then print out the touch and you can see if the player passed the touch from its view to you.
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
NSLog(#"Video Touched?? %#",touches);
}
We need to place a transparent view over the movie player and handle touches for that view.

imagemap in objective c

i want to make something like this
http://www.htmlcodetutorial.com/images/images_famsupp_220.html
and i want to know if there is class to do it in objective c?
thx
if i understood you correctly, you want to have several sensitive points on an image view?
try adding
-(void) touchesBegan: (NSSet *) touches withEvent: (UIEvent *) event
{
NSLog(#"Touches: %#", touches); //examine this!
}
to your code.
it provides UITouch instances in the touches-set, each having an location point for your views.
checkout
UITouch locationInView:;
regs.
UIWebView supports image maps. If you want a pure Objective-C solution I would recommend using an UIImageView and capture touches where you would like to map the image. Once some one touches the view you can then call the appropriate action.