我想在iPhone中实现翻页触摸事件 [英] I want to implement the flip touch event in iPhone

查看:54
本文介绍了我想在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.

如何在iPhone中进行操作.

How to do it in iPhone.

推荐答案

为此,您必须通过跟踪用户的触摸来跟踪它,这是一个示例方法,当用户将手指向右或向右拖动时,它将执行某些操作.左

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.

    }

}

请注意,当用户放下手指并成为该类的成员时,将设置startTouchPosition.起始位置是用这样的方法设置的

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.

这篇关于我想在iPhone中实现翻页触摸事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆