user1388320
user1388320

Reputation:

Touch button without removing finger from screen

Is there a way to detect the touch inside an UIButton without the user remove the finger from screen?

Example: If you have two buttons and the user tapped the left one then drag the finger to the right one, the application must recognize that you're tapping the right button.

Upvotes: 0

Views: 189

Answers (2)

jimpic
jimpic

Reputation: 5520

You should be able to do this using the already existing button events. For example "Touch Drag Outside", "Touch Up Outside", "Touch Drag Exit", etc.

Just register for these events and see which ones will fit your needs.

Upvotes: 2

Fogmeister
Fogmeister

Reputation: 77621

I'd implement this yourself using the UIViewController.

Instead of using buttons.

Put two views on the screen (one for each button) You can either make these buttons, imageViews or just UIViews but make sure they have userInteractionEnabled = NO;.

Then in the UIViewController use the method touchesBegan and touchesMoved.

I would save some state in the viewController like...

BOOL trackTouch;
UIView *currentView;

Then if the touchesBegan is inside one of your views...

-(void)touchesBegan... (can't remember the full name)
{
    UITouch *touch = [touches anyObject];
    CGPoint point = [touch locationInView:self.view];
    if (CGRectContainsPoint(firstView, point)) {
        trackTouch = YES
        //deal with the initial touch...
        currentView = firstView;  (work out which view you are in and store it)
    } else if (CGRectContainsPoint(secondView, point)) {
        trackTouch = YES
        //deal with the initial touch...
        currentView = secondView;  (work out which view you are in and store it)
    }
}

Then in touchesMoved...

- (void)touchesMoved... (can't remember the full name)
{
    UITouch *touch = [touches anyObject];
    CGPoint point = [touch locationInView:self.view];
    if (CGRectContainsPoint(secondView, point) and currentView != secondView)) {
        // deal with the touch swapping into a new view.
        currentView = secondView;
    } else if (CGRectContainsPoint(firstView, point) and currentView != firstView)) {
        // deal with the touch swapping into a new view.
        currentView = firstView;
    }
}

Something like this anyway.

Upvotes: 0

Related Questions