Help with rotating with 2 fingers and selecting with 1 finger

Discussion in 'iPhone/iPad Programming' started by Moon013, Aug 25, 2008.

  1. macrumors newbie

    Joined:
    Jul 14, 2008
    #1
    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.
     
  2. macrumors member

    davedelong

    Joined:
    Sep 9, 2007
    Location:
    Right here.
    #2
    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
     
  3. thread starter macrumors newbie

    Joined:
    Jul 14, 2008
    #3
    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?
     
  4. macrumors member

    davedelong

    Joined:
    Sep 9, 2007
    Location:
    Right here.
    #4
    Code:
    if ([touches count] >= 2) {
      //dragging with two fingers
    } else {
      //dragging with one finger
    }
     
  5. thread starter macrumors newbie

    Joined:
    Jul 14, 2008
    #5
    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
     

Share This Page