jake9115
jake9115

Reputation: 4084

Constricting UISwipeGestureRecognizer to only detect swipes within the area of a IUImageView

I am currently using the following code to detect swipe gestures in my app:

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

However, I want to restrict the swipe recognition to a portion of the screen as defined by a UImageView. Is there a simple way to do this? Thanks.

Upvotes: 0

Views: 106

Answers (1)

TelKitty
TelKitty

Reputation: 3156

If you know where you UIImageView is, you can test whether the gesture is inside the area:

- (BOOL)pointInside:(CGPoint)point{

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

If the gesture is outside the UIImageview then ignore it.

Upvotes: 1

Related Questions