0

我目前正在使用以下代码来检测我的应用程序中的滑动手势:

- (IBAction)swiperMethod:(UISwipeGestureRecognizer *)sender {
    _sampleText.text=@"hi";
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    UISwipeGestureRecognizer *leftRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swiperMethod:)];
    [leftRecognizer setDirection: UISwipeGestureRecognizerDirectionLeft];
    [[self view] addGestureRecognizer:leftRecognizer];
    // Do any additional setup after loading the view, typically from a nib.
}

但是,我想将滑动识别限制在由 UImageView 定义的屏幕的一部分。有没有一种简单的方法可以做到这一点?谢谢。

4

1 回答 1

1

如果你知道你的 UIImageView 在哪里,你可以测试手势是否在区域内:

- (BOOL)pointInside:(CGPoint)point{

    return (point.y < imageViewBottom && point.y > imageViewTop && point.x < imageViewRight && point.x > imageViewLeft);
}

如果手势在 UIImageview 之外,则忽略它。

于 2013-05-19T08:00:09.773 回答