PDA

View Full Version : Help with rotating with 2 fingers and selecting with 1 finger




Moon013
Aug 25, 2008, 10:42 AM
I wanted to make an application which will generates an animation when i touch image1 and drag it on top of image2.

In addition, I wanted to make it such that when my fingers are on both images and moved, another type of animation will occurs.

I used functions like - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event; for my moving of images.

However, how could I make my program detect 2 fingers instead of only 1? I heard people say about using the UIScrollView, but by using that, I don't think I will still able to move the image? Or am i going to use the <UIScrollViewDelegate> protocol?

Correct me if I am wrong, bit noob here.
Help is greatly appreciated.



davedelong
Aug 25, 2008, 10:48 AM
I wanted to make an application which will generates an animation when i touch image1 and drag it on top of image2.

In addition, I wanted to make it such that when my fingers are on both images and moved, another type of animation will occurs.

I used functions like - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event; for my moving of images.

However, how could I make my program detect 2 fingers instead of only 1? I heard people say about using the UIScrollView, but by using that, I don't think I will still able to move the image? Or am i going to use the <UIScrollViewDelegate> protocol?

Correct me if I am wrong, bit noob here.
Help is greatly appreciated.

To detect multiple touches, you need to make sure that "Multiple Touch" is enabled for the particular UIView (or subclass thereof). Once you do that, you'll find that the NSSet * touches has more than one UITouch object in it. Each UITouch object corresponds to one finger.

HTH,

Dave

Moon013
Aug 25, 2008, 09:18 PM
Thanks for the reply and help given.

So i set my view to allow multipleTouch, but now how do i check if user is using 1 finger dragging or 2 fingers dragging?

davedelong
Aug 25, 2008, 09:28 PM
Thanks for the reply and help given.

So i set my view to allow multipleTouch, but now how do i check if user is using 1 finger dragging or 2 fingers dragging?

if ([touches count] >= 2) {
//dragging with two fingers
} else {
//dragging with one finger
}

Moon013
Aug 25, 2008, 10:17 PM
Thanks again for that fast reply.

This is what i wrote:

UITouch *touch = [touches anyObject];
CGPoint location;

if ([touch view] == image)
{
location = [touch locationInView:image];

if([touches count] == 1)
{
NSLog(@"1");
}

else if ([touches count] == 2)
{
NSLog(@"2");
}
}

It doesn't work, it keep showing only 1...is there something i miss?
*I try 2 fingers by pressing alt/option and press on mouse and drag; tested on simulator