handle hardware mouse in trackpad mode

This commit is contained in:
Jesús A. Álvarez 2020-06-23 19:07:30 +02:00
parent 5ab79e73e2
commit ddfe6201a6
2 changed files with 23 additions and 2 deletions

View File

@ -45,7 +45,21 @@
}
}
- (BOOL)isMouseEvent:(UIEvent *)event {
#if __IPHONE_13_4
if (@available(iOS 13.4, *)) {
return event.buttonMask != 0;
}
#endif
return NO;
}
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
if ([self isMouseEvent:event]) {
[self startDragging];
return;
}
[currentTouches unionSet:touches];
if (currentTouches.count == 1) {
[self firstTouchBegan:touches.anyObject withEvent:event];
@ -67,6 +81,7 @@
}
- (void)touchesMoved:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
if ([self isMouseEvent:event]) return;
UITouch *touch = touches.anyObject;
CGPoint touchLoc = [touch locationInView:self];
previousTouchLoc = [touch previousLocationInView:self];
@ -91,6 +106,10 @@
}
- (void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
if ([self isMouseEvent:event]) {
[self stopDragging];
return;
}
[currentTouches minusSet:touches];
if (currentTouches.count > 0) {
return;

View File

@ -147,8 +147,10 @@ API_AVAILABLE(ios(13.4))
#ifdef __IPHONE_13_4
if (@available(iOS 13.4, *)) {
interaction = [[UIPointerInteraction alloc] initWithDelegate: self];
[self.view addInteraction:interaction];
if (interaction == nil) {
interaction = [[UIPointerInteraction alloc] initWithDelegate: self];
[self.view addInteraction:interaction];
}
}
#endif