在ios中滑动模式匹配

时间:2014-01-20 05:48:45

标签: ios iphone gesture-recognition

我正在尝试创建一个与滑动图案匹配的应用来显示特定图像。目前我正在使用按钮在按钮点击时显示图像。我想检测滑动图案并相应地显示图像。 欢迎任何这方面的帮助。请帮忙

2 个答案:

答案 0 :(得分:4)

试试这个:

.h文件添加“UIGestureRecognizerDelegate

.m文件(如果你想在self.view中)

   //LEFT Swipe
   UISwipeGestureRecognizer *swipeLeft = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipedLeft:)];
   [swipeLeft setDirection:UISwipeGestureRecognizerDirectionLeft ];
   [self.view addGestureRecognizer:swipeLeft];

   //Right Swipe
    UISwipeGestureRecognizer *swipeRight = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipedRight:)];
    [swipeRight setDirection:UISwipeGestureRecognizerDirectionRight ];
    [self.view addGestureRecognizer:swipeRight];

    //Down Swipe        
    UISwipeGestureRecognizer *swipeDown = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeDown:)];
    [swipeDown setDirection:UISwipeGestureRecognizerDirectionDown ];
    [self.view addGestureRecognizer:swipeDown];

    //Up Swipe       
    UISwipeGestureRecognizer *swipeUp = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeUp:)];
    [swipeUp setDirection:UISwipeGestureRecognizerDirectionUp ];
    [self.view addGestureRecognizer:swipeUp];

- (void)swipedRight:(UISwipeGestureRecognizer *)recognizer
{   // Do your stuff while swipedRight
}

- (void)swipedLeft:(UISwipeGestureRecognizer *)recognizer
{   // Do your stuff while swipedLeft
}
- (void)swipeDown:(UISwipeGestureRecognizer *)recognizer
{   // Do your stuff while swipeDown
}
- (void)swipeUp:(UISwipeGestureRecognizer *)recognizer
{   // Do your stuff while swipeUp
}

修改

用于循环滑动检测

检查来自here

Sixten Otto 给出的答案

还要检查here

中的此帖子

用于角度滑动

检查此link

愿它能帮到你。

快乐的编码......:)

答案 1 :(得分:2)

试试这个

UISwipeGestureRecognizer *swipe = [[UISwipeGestureRecognizer alloc]
                                        initWithTarget:self
                                                action:@selector(swipeAction)];
swipe.direction = UISwipeGestureRecognizerDirectionRight;

[self.view addGestureRecognizer:swipe];


 -(void)swipeAction

{

}