dimanche 28 juin 2015

iOS touch(es) blocking issue

I am encoutering a strange issue with an iOS application that I'm currently working on, issue related to touches.

For exemplification, the layout of the app looks something like this (its quite basic, nothing fancy, just some buttons and a touch area):

Application layout

A is the touch area (its a CONTAINER which has a View inside, view that displays an image , image that is affected by the way im touching the area).

B is a simple iOS button (the one you create by default with XCODE , with just a changed background color and size (width/height).

Now , the issue: it only happens some times, I could not yet figure out why and when, but I can reproduce it sometimes. Basically, when clicking B , touches on A (with a finger from the left hand) behave strange: i am receiving the touchesMoved event, but the touch position is the position of the touch on B, hence the movement of the image in A does not happen, and when it happens (after removing the right hand finger from B), the movement behaves as if the touch was at the B position.

Here is part of the code , the part that handles touches, in the ViewController attached to the A view. I have removed some of the code that I dont think its related to my issue, to keep things cleaner.

-(void)touchesBegan:(nonnull NSSet<UITouch *> *)touches withEvent:(nullable UIEvent *)event{

    NSLog(@"A View touched : %d", [touches count]);
    UITouch *touch = [[event allTouches] anyObject];
    CGPoint touchLocation = [touch locationInView: _theAView];
    NSLog(@"Touch at %f %f", touchLocation.x, touchLocation.y);
    initialTouchX = touchLocation.x;
    initialTouchY = touchLocation.y;    


}

-(void)touchesMoved:(nonnull NSSet<UITouch *> *)touches withEvent:(nullable UIEvent *)event{

    /*
    some code was here handling time, to only handle moving every X milliseconds
    */
    UITouch *touch = [[event allTouches] anyObject];
    CGPoint touchLocation = [touch locationInView:theAView];


    /*
    code handling the display of the image , removed
    */
    initialTouchX = touchLocation.x;
    initialTouchY = touchLocation.y;

}

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {

}
- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event {

}

As for the code of the B button, its just a basic IBAction, which calls a function with a parameter:

- (IBAction)btnDown:(id)sender {
    //call some function here 
}

Two things to note:

1) in the code above, "theAView" reffers to the view in the A area. 2) the 1st part of code (the one with the touches) resides in a different ViewController; the 2nd part of the code, for the button, resides in the default ViewController file that XCODE creates when creating a project.

I also tried enabling multitouch on both the A view and the B button, but the problem is still there.

Any help is appreciated.

Thanks in advance.

Aucun commentaire:

Enregistrer un commentaire