iOS Question [Solved] Multitouch and standard touch event on the same page

roumei

Active Member
Licensed User
I'd like to use two panels with a different handling of the touch events on the same page:
- The first panel uses the MultiTouch implementation from here https://www.b4x.com/android/forum/threads/multitouch-event.87027/ .
- The second panel should use the standard touch event.
At the moment, the MultiTouch code replaces the standard touch events for all panels. Erel mentions in the post above that the standard touch event should be raised if multipleTouchEnabled is set to False. I tried to change the code but my knowledge of Objective-C is practically zero.

Any help would be greatly appreciated!

This is the OBJC code:

Objective-C:
#if OBJC
- (NSArray*)UITouchToPoint:(UITouch*)t :(UIView*)view {
    CGPoint p = [t locationInView:view];
    return @[@(p.x), @(p.y)];
}
@end

@implementation B4IPanelView (override)

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    if ([B4IObjectWrapper raiseEvent:self :@"_multitouchbegan:" :@[[touches allObjects]]] == false)
        [super touchesMoved:touches withEvent:event];
}

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
    if ([B4IObjectWrapper raiseEvent:self :@"_multitouchmoved:" :@[[touches allObjects]]] == false)
        [super touchesMoved:touches withEvent:event];
  
}

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
    if ([B4IObjectWrapper raiseEvent:self :@"_multitouchended:" :@[[touches allObjects]]] == false)
        [super touchesMoved:touches withEvent:event];
}

#End If
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Use this code:
B4X:
#if OBJC
- (NSArray*)UITouchToPoint:(UITouch*)t :(UIView*)view {
    CGPoint p = [t locationInView:view];
    return @[@(p.x), @(p.y)];
}
@end

@implementation B4IPanelView (override)

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    if (self.multipleTouchEnabled) {
        if ([B4IObjectWrapper raiseEvent:self :@"_multitouchbegan:" :@[[touches allObjects]]] == false)
        [super touchesMoved:touches withEvent:event];
    } else  {
        for (UITouch *u in touches) {
            CGPoint p = [u locationInView:self];
            [B4IObjectWrapper raiseEvent:self :@"_touch:::" :@[@0, @(p.x), @(p.y)]];
        }
    }
}

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
 
    if (self.multipleTouchEnabled) {
         if ([B4IObjectWrapper raiseEvent:self :@"_multitouchmoved:" :@[[touches allObjects]]] == false)
                [super touchesMoved:touches withEvent:event];
    } else  {
        for (UITouch *u in touches) {
            CGPoint p = [u locationInView:self];
            [B4IObjectWrapper raiseEvent:self :@"_touch:::" :@[@2, @(p.x), @(p.y)]];
        }
    }
   
}

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
    
    if (self.multipleTouchEnabled) {
        if ([B4IObjectWrapper raiseEvent:self :@"_multitouchended:" :@[[touches allObjects]]] == false)
        [super touchesMoved:touches withEvent:event];
    } else  {
        for (UITouch *u in touches) {
            CGPoint p = [u locationInView:self];
            [B4IObjectWrapper raiseEvent:self :@"_touch:::" :@[@1, @(p.x), @(p.y)]];
        }
    }
}

#End If
 
Upvote 0
Top