2nd time - completely resolving conflict between custom tap gesture & onscreen control taps

This commit is contained in:
True Zhuanjia
2024-08-16 21:45:50 +08:00
parent 6e3c982a22
commit 53e68258f3
7 changed files with 44 additions and 57 deletions
@@ -483,7 +483,7 @@ BOOL isCustomResolution(CGSize res) {
- (void)showCustomOSCTip {
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:[LocalizationHelper localizedStringForKey:@"Rebase in Stream View"]
message:[LocalizationHelper localizedStringForKey:@"Tap 5 fingers to change on-screen controller layout in stream view"]
message:[LocalizationHelper localizedStringForKey:@"Tap %d fingers to change on-screen controller layout in stream view", OSC_TOOL_FINGERS]
preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *okAction = [UIAlertAction actionWithTitle:[LocalizationHelper localizedStringForKey: @"Got it!"]
style:UIAlertActionStyleDefault
@@ -518,7 +518,7 @@ BOOL isCustomResolution(CGSize res) {
// [self.keyboardToggleFingerNumSlider setValue:3.0];
// [self keyboardToggleFingerNumSliderMoved];
[self keyboardToggleFingerNumSliderMoved]; // go to exclude 5 fingers
[self.onscreenControllerLabel setText:[LocalizationHelper localizedStringForKey: @"Tap 5 Fingers to Change OSC Layout in Stream View"]];
[self.onscreenControllerLabel setText:[LocalizationHelper localizedStringForKey: @"Tap %d Fingers to Change OSC Layout in Stream View", OSC_TOOL_FINGERS]];
[self showCustomOSCTip];
justEnteredSettingsViewDoNotOpenOscLayoutTool = false;
//if (self.layoutOnScreenControlsVC.isBeingPresented == NO)
@@ -611,7 +611,7 @@ BOOL isCustomResolution(CGSize res) {
if(customOscEnabled) {
// [self.keyboardToggleFingerNumSlider setValue:3.0];
// [self.keyboardToggleFingerNumLabel setText:[LocalizationHelper localizedStringForKey:@"To Toggle Local Keyboard: Tap %d Fingers", (uint16_t)self.keyboardToggleFingerNumSlider.value]];
[self.onscreenControllerLabel setText:[LocalizationHelper localizedStringForKey: @"Tap 5 Fingers to Change OSC Layout in Stream View"]];
[self.onscreenControllerLabel setText:[LocalizationHelper localizedStringForKey: @"Tap %d Fingers to Change OSC Layout in Stream View", OSC_TOOL_FINGERS]];
[self keyboardToggleFingerNumSliderMoved]; // go exclude 5 fingers
//if (self.layoutOnScreenControlsVC.isBeingPresented == NO)
}
@@ -814,9 +814,9 @@ BOOL isCustomResolution(CGSize res) {
CGFloat sliderValue = self.keyboardToggleFingerNumSlider.value;
if(customOscEnabled){
// exclude 5 fingers when custom osc is enabled
if(sliderValue > OSC_TOOL_FINGERS - 1 && sliderValue < OSC_TOOL_FINGERS) [self.keyboardToggleFingerNumSlider setValue:4.0];
if(sliderValue >= OSC_TOOL_FINGERS && sliderValue < OSC_TOOL_FINGERS + 1) [self.keyboardToggleFingerNumSlider setValue:6.0];
// exclude OSC_TOOL_FINGERS when custom osc is enabled
if(sliderValue > OSC_TOOL_FINGERS - 1 && sliderValue < OSC_TOOL_FINGERS) [self.keyboardToggleFingerNumSlider setValue: OSC_TOOL_FINGERS - 1];
if(sliderValue >= OSC_TOOL_FINGERS && sliderValue < OSC_TOOL_FINGERS + 1) [self.keyboardToggleFingerNumSlider setValue: OSC_TOOL_FINGERS + 1];
}
sliderValue = self.keyboardToggleFingerNumSlider.value;
@@ -63,7 +63,6 @@
- (void)configOscLayoutTool{
[self->_streamView removeGestureRecognizer:_oscLayoutTapRecoginizer];
if((_settings.touchMode.intValue == RELATIVE_TOUCH || _settings.touchMode.intValue == REGULAR_NATIVE_TOUCH) && _settings.onscreenControls.intValue == OnScreenControlsLevelCustom){
_oscLayoutTapRecoginizer = [[CustomTapGestureRecognizer alloc] initWithTarget:self action:@selector(layoutOSC)];
_oscLayoutTapRecoginizer.numberOfTouchesRequired = OSC_TOOL_FINGERS; //tap a predefined number of fingers to open osc layout tool
@@ -71,7 +70,7 @@
_oscLayoutTapRecoginizer.delaysTouchesBegan = NO;
_oscLayoutTapRecoginizer.delaysTouchesEnded = NO;
[self->_streamView addGestureRecognizer:_oscLayoutTapRecoginizer]; // all gesture recognizers created in this view controller will be added to the streamview instead of self.view
[self.view addGestureRecognizer:_oscLayoutTapRecoginizer]; //
/* sets a reference to the correct 'LayoutOnScreenControlsViewController' depending on whether the user is on an iPhone or iPad */
_layoutOnScreenControlsVC = [[LayoutOnScreenControlsViewController alloc] init];
BOOL isIPhone = ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPhone);
@@ -94,28 +93,25 @@
[self presentViewController:cmdManViewController animated:YES completion:nil];
}
- (void)configGestures{
[self->_streamView removeGestureRecognizer:_slideToSettingsRecognizer];
- (void)configSwipeGestures{
_slideToSettingsRecognizer = [[CustomEdgeSwipeGestureRecognizer alloc] initWithTarget:self action:@selector(edgeSwiped)];
_slideToSettingsRecognizer.edges = _settings.slideToSettingsScreenEdge.intValue;
_slideToSettingsRecognizer.normalizedThresholdDistance = _settings.slideToSettingsDistance.floatValue;
_slideToSettingsRecognizer.delaysTouchesBegan = NO;
_slideToSettingsRecognizer.delaysTouchesEnded = NO;
[self->_streamView addGestureRecognizer:_slideToSettingsRecognizer];
[self.view addGestureRecognizer:_slideToSettingsRecognizer];
[self->_streamView removeGestureRecognizer:_slideToCmdToolRecognizer];
_slideToCmdToolRecognizer = [[CustomEdgeSwipeGestureRecognizer alloc] initWithTarget:self action:@selector(presentCommandManagerViewController)];
if(_settings.slideToSettingsScreenEdge.intValue == UIRectEdgeLeft) _slideToCmdToolRecognizer.edges = UIRectEdgeRight;
else _slideToCmdToolRecognizer.edges = UIRectEdgeLeft; // _commandManager triggered by sliding from another side.
_slideToCmdToolRecognizer.normalizedThresholdDistance = _settings.slideToSettingsDistance.floatValue;
_slideToCmdToolRecognizer.delaysTouchesBegan = NO;
_slideToCmdToolRecognizer.delaysTouchesEnded = NO;
[self->_streamView addGestureRecognizer:_slideToCmdToolRecognizer];
[self.view addGestureRecognizer:_slideToCmdToolRecognizer];
}
- (void)configZoomGesture{
[_scrollView removeFromSuperview];
if (_settings.touchMode.intValue == ABSOLUTE_TOUCH) {
_scrollView = [[UIScrollView alloc] initWithFrame:self.view.frame];
#if !TARGET_OS_TV
@@ -130,20 +126,31 @@
// Add StreamView inside a UIScrollView for absolute mode
[_scrollView addSubview:_streamView];
[self.view addSubview:_scrollView];
return;
}
[self.view addSubview:_streamView];
else{
// Add streamView directly to self.view in other touch modes
[self.view addSubview:_streamView];
}
}
// key implementation of reconfiguring streamview after realtime setting menu is closed.
- (void)reConfigStreamViewRealtime{
//[self.view removeGestureRecognizer:]
//first, remove all gesture recognizers:
for (UIGestureRecognizer *recognizer in _streamView.gestureRecognizers) {
[_streamView removeGestureRecognizer:recognizer];
}
for (UIGestureRecognizer *recognizer in self.view.gestureRecognizers) {
[self.view removeGestureRecognizer:recognizer];
}
_settings = [[[DataManager alloc] init] getSettings]; //StreamFrameViewController retrieve the settings here.
[self configOscLayoutTool];
[self configGestures];
[self configSwipeGestures];
[self configZoomGesture];
[self->_streamView disableOnScreenControls]; //don't know why but this must be called outside the streamview class, just put it here. execute in streamview class cause hang
[self.mainFrameViewcontroller reloadStreamConfig]; // reload streamconfig
_controllerSupport = [[ControllerSupport alloc] initWithConfig:self.streamConfig delegate:self]; // reload controllerSupport obj, this is mandatory for OSC reload,especially when the stream view is launched without OSC
[_streamView setupStreamView:_controllerSupport interactionDelegate:self config:self.streamConfig]; //reinitiate setupStreamView process.
[self->_streamView reloadOnScreenControlsRealtimeWith:(ControllerSupport*)_controllerSupport
@@ -155,6 +162,9 @@
selector:@selector(updateStatsOverlay)
userInfo:nil
repeats:_settings.statsOverlay];
NSLog(@"frameview gestures: %d", (uint32_t)[self.view.gestureRecognizers count]);
NSLog(@"streamview gestures: %d", (uint32_t)[_streamView.gestureRecognizers count]);
}
@@ -248,7 +258,8 @@
_inactivityTimer = nil;
_streamView = [[StreamView alloc] initWithFrame:self.view.frame];
[_streamView setupStreamView:_controllerSupport interactionDelegate:self config:self.streamConfig];
//[_streamView setupStreamView:_controllerSupport interactionDelegate:self config:self.streamConfig];
[self reConfigStreamViewRealtime]; // call this method again to make sure all gestures are configured & added to the superview(self.view), including the gestures added from inside the streamview.
#if TARGET_OS_TV
if (!_menuTapGestureRecognizer || !_menuDoubleTapGestureRecognizer || !_playPauseTapGestureRecognizer) {
@@ -269,8 +280,8 @@
[self.view addGestureRecognizer:_playPauseTapGestureRecognizer];
#else
[self configGestures]; // swipe & exit gesture configured here
[self configOscLayoutTool]; //_oscLayoutTapRecoginizer will be added or removed to the view here
//[self configSwipeGestures]; // swipe & exit gesture configured here
//[self configOscLayoutTool]; //_oscLayoutTapRecoginizer will be added or removed to the view here
#endif
_tipLabel = [[UILabel alloc] init];
@@ -328,26 +339,6 @@
object: nil];
#endif
// Only enable scroll and zoom in absolute touch mode
if (_settings.touchMode.intValue == ABSOLUTE_TOUCH) {
_scrollView = [[UIScrollView alloc] initWithFrame:self.view.frame];
#if !TARGET_OS_TV
[_scrollView.panGestureRecognizer setMinimumNumberOfTouches:2];
[_scrollView.panGestureRecognizer setMaximumNumberOfTouches:2]; // reduce competing with keyboardToggleRecognizer in StreamView.
#endif
[_scrollView setShowsHorizontalScrollIndicator:NO];
[_scrollView setShowsVerticalScrollIndicator:NO];
[_scrollView setDelegate:self];
[_scrollView setMaximumZoomScale:10.0f];
// Add StreamView inside a UIScrollView for absolute mode
[_scrollView addSubview:_streamView];
[self.view addSubview:_scrollView];
}
else {
// Add StreamView directly in relative mode
[self.view addSubview:_streamView];
}
[self.view addSubview:_stageLabel];
[self.view addSubview:_spinner];
[self.view addSubview:_tipLabel];