Question

I am trying to detect swipes in a very specific way, and am having mixed results. My first problem was recognizing swipes in only a certain region of the screen, which is now solved. My current problem is this: Let's say I have a thing column in my view, and I make the dimensions of that column correspond to my Gesture Recognizer. When using the app, the swipe must begin within those dimensions to be recognized as a swipe. Instead, I need to recognize the swipe even if the user started swiping outside the column's area. In fact, I don't even care if it was a swipe, even a tap or something is fine, I just want to know if the user's fingers have ever been within that column (and in this case they would definitely started the swipe from outside the column's area).

Here is my current code which words, but the swipe must start within the column:

- (IBAction)swiperMethod:(UISwipeGestureRecognizer *)sender {
    CGPoint point = [sender locationInView:self.view];
    if(point.y < 316 && point.y > 76 && point.x < 234 && point.x > 164)
    {
        _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.
}

Can someone please show me how to make the swipe (or whatever gesture, I don't care about it specifically being a swipe) recognized even if the user just drag's his/her finger across this area?

Thanks!

Was it helpful?

Solution

This method works!

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
    UITouch * touch = [[event allTouches] anyObject];
    CGPoint point = [touch locationInView:touch.view];
    if(point.y < 316 && point.y > 76 && point.x < 234 && point.x > 164)
    {
        _sample.image = [UIImage imageNamed:@"normal.png"];
    }
    else
    {
        _star.image = [UIImage imageNamed:@"alternate.png"];
    }

}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top