【问题标题】:Swipe pattern matching in ios [closed]ios中的滑动模式匹配[关闭]
【发布时间】:2014-01-20 05:48:45
【问题描述】:

我正在尝试制作一个匹配滑动模式以显示特定图像的应用。目前我正在使用按钮在按钮单击时显示图像。我想检测滑动模式并相应地显示图像。 欢迎在这个方向提供任何帮助。请帮忙

【问题讨论】:

  • 在按钮点击时,点击事件会发生,你需要做一些动画之类的事情,但如果你想要“滑动效果”,那么你必须在按钮上添加滑动手势。所以只是想建议从你的脑海中删除这个你会在按钮点击时获得滑动效果..你需要滑动按钮..不要点击按钮

标签: ios iphone gesture-recognition


【解决方案1】:

试试这个:

.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
}

编辑:

用于圆形滑动检测

查看hereSixten Otto 给出的答案

也可以从here查看这个帖子

角度滑动

检查这个link

希望对你有帮助。

编码愉快...:)

【讨论】:

  • 感谢您的帮助。但我需要检查某些滑动模式。表示用户是否滑动 L、正方形或圆形。我可以这样做吗?并且根据模式我必须显示某些图像
  • UISwipeGestureRecognizer 只给你四个手势左、右、上、下。也许你必须使用第三方库来满足你的要求,并以你想要的正确方式提出问题。
  • 我想检测用户是否刷了 L、正方形等。你能推荐任何我可以查看的第三方库吗?
  • 检查我的编辑答案@slaveCoder
【解决方案2】:

试试这个

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

[self.view addGestureRecognizer:swipe];


 -(void)swipeAction

{

}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-10-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-05-17
    • 1970-01-01
    相关资源
    最近更新 更多