Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/38.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 识别用户剪切/滑动手势(UISweepGestureRecognitor)_Iphone_Cocoa Touch_Uicontrol - Fatal编程技术网

Iphone 识别用户剪切/滑动手势(UISweepGestureRecognitor)

Iphone 识别用户剪切/滑动手势(UISweepGestureRecognitor),iphone,cocoa-touch,uicontrol,Iphone,Cocoa Touch,Uicontrol,我使用下面的代码并为“self.view”工作,但不适用于imageview和direction只能添加一个方向如何使用四个方向右、左、uo、下 UISwipeGestureRecognizer *swipe =[[UISwipeGestureRecognizer alloc]initWithTarget:selfaction:@selector(sr)]; swipe.direction =UISwipeGestureRecognizerDirectionRight; [imageview a

我使用下面的代码并为“self.view”工作,但不适用于imageview和direction只能添加一个方向如何使用四个方向右、左、uo、下

UISwipeGestureRecognizer *swipe =[[UISwipeGestureRecognizer alloc]initWithTarget:selfaction:@selector(sr)];
swipe.direction =UISwipeGestureRecognizerDirectionRight;
[imageview addGestureRecognizer:swipe];
[swipe release];
代表

touchesBegan: 

touchesEnded:

如果您对仅在iOS 3.2+上运行的应用程序感到满意,那么最好的方法是使用UIgestureRecognitor API类。事实上,有一个UISweepGestureRecognitor子类

要想做你想做的事,请执行以下操作:

UISwipeGestureRecognizer *swipe = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(doSomething:)];
swipe.direction = UISwipeGestureRecognizerDirectionRight;
[yourImageView addGestureRecognizer:swipe];
[swipe release];
swipeRecognizer.direction = UISwipeGestureRecognizerDirectionRight | UISwipeGestureRecognizerDirectionLeft;

要更改为任何其他方向,请查看上面的文档链接-所有四个方向都有一个常量。

尝试启用交互:

yourImageView.userInteractionEnabled = YES;
再加上一些方向,比如:

UISwipeGestureRecognizer *swipe = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(doSomething:)];
swipe.direction = UISwipeGestureRecognizerDirectionRight;
[yourImageView addGestureRecognizer:swipe];
[swipe release];
swipeRecognizer.direction = UISwipeGestureRecognizerDirectionRight | UISwipeGestureRecognizerDirectionLeft;

//----在imageview分配中添加此代码----//

        imageview.userInteractionEnabled = YES;
对于四个方向,您必须使用两个UISweepGestureRecognitor:-

      UISwipeGestureRecognizer *swipeRightLeft =[[UISwipeGestureRecognizer     alloc]initWithTarget:selfaction:@selector(sr)];

   [swipeRightLeft setDirection:(UISwipeGestureRecognizerDirectionRight |UISwipeGestureRecognizerDirectionLeft )];

   [imageview addGestureRecognizer:swipeRightLeft];

    [swipeRightLeft release];

    UISwipeGestureRecognizer *swipeUpDown =[[UISwipeGestureRecognizer     alloc]initWithTarget:selfaction:@selector(sr)];

      [swipeUpDown setDirection:(UISwipeGestureRecognizerDirectionUp | UISwipeGestureRecognizerDirectionDown )];

    [imageview addGestureRecognizer:swipeUpDown];

    [swipeUpDown release];

剪切视图意味着什么?意味着开始触摸,例如从控件的左侧到右侧,这在iPhone世界中并不完全是我们所说的。。。或者至少我从来没听说过像《水果忍者》中的割果或者《割断绳索》中的割断绳索这样的话,让我来看看:在iPhone世界里,这叫做“割断”。谢谢你,我使用这个代码为“self.view”工作,但对“imageview”不起作用。嘿,如果你找到了解决方案,你就可以把它放在回答中。。。因为我在imageView中面临同样的问题,手势作用于标签、视图等。。。。如果你得到它,请发送它的解决方案