rkb
rkb

Reputation: 11231

I want to implement the flip touch event in iPhone

In my application I have two images which are arranged in circle.

I want to imeplement something like when user flips his finger downwards or in circle the position of the images must be swapped.

How to do it in iPhone.

Upvotes: 0

Views: 1190

Answers (1)

Daniel
Daniel

Reputation: 22405

For this you must keep track of it by tracking the users touches, here is an example method that will do something when the user drags his finger to the right or left

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event

{

    UITouch *touch = [touches anyObject];

    CGPoint currentTouchPosition = [touch locationInView:self];



    // If the swipe tracks correctly.

    if (fabsf(startTouchPosition.x - currentTouchPosition.x) >= HORIZ_SWIPE_DRAG_MIN &&

        fabsf(startTouchPosition.y - currentTouchPosition.y) <= VERT_SWIPE_DRAG_MAX)

    {

        // It appears to be a swipe.

        if (startTouchPosition.x < currentTouchPosition.x)

            [delegate doLeftTransition];

        else

            [delegate doRightTransition];

    }

    else

    {

        // Process a non-swipe event.

    }

}

Notice here that startTouchPosition is set when the user puts down his finger and is a member of the class. The start position is set in a method like this

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{

    UITouch *touch = [touches anyObject];

    startTouchPosition = [touch locationInView:self];
}

The above sample code does something when the user swipes to the right or left, but you can easily adjust it to figure out when the user swipes down or in a circle in the same fashion as the sample above. Once you figure out when the user has done such gesture you can swap your images.

Upvotes: 1

Related Questions