fix: widget layout tool disfunction after display orientation change

This commit is contained in:
TrueZhuanjia committed 2025-07-27 00:08:10 +08:00
1 parent 6a3e1d8a88
commit dd9ad9728a
5 files changed
+52 -30

No files matched your search

@@ -22,8 +22,10 @@ NS_ASSUME_NONNULL_BEGIN
@property NSMutableArray <OSCProfile *> *currentProfiles; @property NSMutableArray <OSCProfile *> *currentProfiles;
+ (OSCProfilesManager *) sharedManager:(CGRect)viewBounds; + (OSCProfilesManager *)sharedManager:(CGRect)viewBounds;
+ (void) setOnScreenWidgetViewsSet:(NSMutableSet* )set; + (void)setOnScreenWidgetViewsSet:(NSMutableSet* )set;
+ (void)setLayoutViewBounds:(CGRect)bounds;
#pragma mark - Getters #pragma mark - Getters
/** /**
+16 -8
View File
@@ -18,15 +18,15 @@
@implementation OSCProfilesManager @implementation OSCProfilesManager
static NSMutableSet *OnScreenWidgetViews; static NSMutableSet *OnScreenWidgetViews;
static CGRect streamViewBounds; static CGRect layoutViewBounds;
#pragma mark - Initializer #pragma mark - Initializer
+ (OSCProfilesManager *) sharedManager:(CGRect)viewBounds { + (OSCProfilesManager *) sharedManager:(CGRect)viewBounds {
static OSCProfilesManager *_sharedManager = nil; static OSCProfilesManager *_sharedManager = nil;
static dispatch_once_t onceToken; static dispatch_once_t onceToken;
streamViewBounds = viewBounds; layoutViewBounds = viewBounds;
NSLog(@"bounds width: %f, height: %f", streamViewBounds.size.width, streamViewBounds.size.height); NSLog(@"bounds width: %f, height: %f", layoutViewBounds.size.width, layoutViewBounds.size.height);
dispatch_once(&onceToken, ^{ dispatch_once(&onceToken, ^{
_sharedManager = [[self alloc] init]; _sharedManager = [[self alloc] init];
}); });
@@ -38,10 +38,14 @@ static CGRect streamViewBounds;
#pragma mark - Class Helper Methods #pragma mark - Class Helper Methods
+ (void) setOnScreenWidgetViewsSet:(NSMutableSet* )set{ + (void)setOnScreenWidgetViewsSet:(NSMutableSet* )set{
OnScreenWidgetViews = set; OnScreenWidgetViews = set;
} }
+ (void)setLayoutViewBounds:(CGRect)bounds{
layoutViewBounds = bounds;
}
/** /**
* Returns the profile whose 'name' property has a value that is equal to the 'name' passed into the method * Returns the profile whose 'name' property has a value that is equal to the 'name' passed into the method
*/ */
@@ -297,17 +301,21 @@ static CGRect streamViewBounds;
} }
- (CGPoint)normalizeWidgetPosition:(CGPoint)position { - (CGPoint)normalizeWidgetPosition:(CGPoint)position {
CGPoint newPosition = position;
if(position.x > 1.0 && position.y >1.0){ if(position.x > 1.0 && position.y >1.0){
position.x = position.x / streamViewBounds.size.width; position.x = position.x / layoutViewBounds.size.width;
position.y = position.y / streamViewBounds.size.height; position.y = position.y / layoutViewBounds.size.height;
} }
// asdfsda;
NSLog(@"sef.view bounds: %f, %f", layoutViewBounds.size.width, layoutViewBounds.size.height);
NSLog(@"position: %f, %f, denormalized position: %f, %f", position.x, position.y, newPosition.x, newPosition.y);
return position; return position;
} }
- (CGPoint)denormalizeWidgetPosition:(CGPoint)position { - (CGPoint)denormalizeWidgetPosition:(CGPoint)position {
if(position.x < 1.0 && position.y < 1.0){ if(position.x < 1.0 && position.y < 1.0){
position.x = position.x * streamViewBounds.size.width; position.x = position.x * layoutViewBounds.size.width;
position.y = position.y * streamViewBounds.size.height; position.y = position.y * layoutViewBounds.size.height;
} }
return position; return position;
} }
@@ -31,6 +31,7 @@
CGRect controllerLoadedBounds; CGRect controllerLoadedBounds;
bool widgetViewSelected; bool widgetViewSelected;
bool controllerLayerSelected; bool controllerLayerSelected;
bool viewWillBeResized;
__weak IBOutlet NSLayoutConstraint *toolbarTopConstraintiPhone; __weak IBOutlet NSLayoutConstraint *toolbarTopConstraintiPhone;
__weak IBOutlet NSLayoutConstraint *toolbarTopConstraintiPad; __weak IBOutlet NSLayoutConstraint *toolbarTopConstraintiPad;
UIColor* trashCanStoryBoardColor; UIColor* trashCanStoryBoardColor;
@@ -71,11 +72,13 @@
} }
- (CGPoint)denormalizeWidgetPosition:(CGPoint)position { - (CGPoint)denormalizeWidgetPosition:(CGPoint)position {
// NSLog(@"position: %f, %f", position.x, position.y);
CGPoint newPosition = position;
if(position.x < 1.0 && position.y < 1.0){ if(position.x < 1.0 && position.y < 1.0){
position.x = position.x * self.view.bounds.size.width; newPosition.x = position.x * self.view.bounds.size.width;
position.y = position.y * self.view.bounds.size.height; newPosition.y = position.y * self.view.bounds.size.height;
} }
return position; return newPosition;
} }
- (void)reloadLegacyOnScreenControls{ - (void)reloadLegacyOnScreenControls{
@@ -140,6 +143,7 @@
//isToolbarHidden = NO; // keeps track if the toolbar is hidden up above the screen so that we know whether to hide or show it when the user taps the toolbar's hide/show button //isToolbarHidden = NO; // keeps track if the toolbar is hidden up above the screen so that we know whether to hide or show it when the user taps the toolbar's hide/show button
_quickSwitchEnabled = false; _quickSwitchEnabled = false;
viewWillBeResized = false;
/* add curve to bottom of chevron tab view */ /* add curve to bottom of chevron tab view */
UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:self.chevronView.bounds byRoundingCorners:(UIRectCornerBottomLeft | UIRectCornerBottomRight) cornerRadii:CGSizeMake(10.0, 10.0)]; UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:self.chevronView.bounds byRoundingCorners:(UIRectCornerBottomLeft | UIRectCornerBottomRight) cornerRadii:CGSizeMake(10.0, 10.0)];
@@ -268,14 +272,18 @@
} }
- (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator{ - (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator{
viewWillBeResized = true;
//if(CGSizeEqualToSize(size, self.view.frame.size)) return;
[self saveTapped:nil]; [self saveTapped:nil];
} }
- (void)deviceOrientationDidChange{ - (void)deviceOrientationDidChange{
[self performSelector:@selector(handleOrientationChangeForOnScreenWidgets) withObject:self afterDelay:1]; [self performSelector:@selector(handleOrientationChangeForOnScreenWidgets) withObject:self afterDelay:0.05];
} }
- (void)handleOrientationChangeForOnScreenWidgets{ - (void)handleOrientationChangeForOnScreenWidgets{
if(!viewWillBeResized) return;
viewWillBeResized = false;
_oscProfilesTableViewController.layoutViewBounds = self.view.bounds; _oscProfilesTableViewController.layoutViewBounds = self.view.bounds;
[OSCProfilesManager setOnScreenWidgetViewsSet:self.onScreenWidgetViews]; // pass the keyboard button dict to profiles manager [OSCProfilesManager setOnScreenWidgetViewsSet:self.onScreenWidgetViews]; // pass the keyboard button dict to profiles manager
[self reloadOnScreenWidgetViews]; [self reloadOnScreenWidgetViews];
@@ -641,6 +649,7 @@
/* show pop up notification that lets users choose to save the current OSC layout configuration as a profile they can load when they want. User can also choose to cancel out of this pop up */ /* show pop up notification that lets users choose to save the current OSC layout configuration as a profile they can load when they want. User can also choose to cancel out of this pop up */
- (IBAction) saveTapped:(id)sender { - (IBAction) saveTapped:(id)sender {
[OSCProfilesManager setLayoutViewBounds:self.view.bounds];
if([self->profilesManager updateSelectedProfile:self.layoutOSC.OSCButtonLayers]){ if([self->profilesManager updateSelectedProfile:self.layoutOSC.OSCButtonLayers]){
UIAlertController * savedAlertController = [UIAlertController alertControllerWithTitle: [NSString stringWithFormat:@""] message: [LocalizationHelper localizedStringForKey:@"Current profile updated successfully"] preferredStyle:UIAlertControllerStyleAlert]; UIAlertController * savedAlertController = [UIAlertController alertControllerWithTitle: [NSString stringWithFormat:@""] message: [LocalizationHelper localizedStringForKey:@"Current profile updated successfully"] preferredStyle:UIAlertControllerStyleAlert];
@@ -1518,21 +1518,6 @@ BOOL isCustomResolution(CGSize res) {
[self.enableOswForNativeTouchSwitch addTarget:self action:@selector(enableOswForNativeTouchSwitchFlipped:) forControlEvents:UIControlEventValueChanged]; [self.enableOswForNativeTouchSwitch addTarget:self action:@selector(enableOswForNativeTouchSwitchFlipped:) forControlEvents:UIControlEventValueChanged];
[self enableOswForNativeTouchSwitchFlipped:self.enableOswForNativeTouchSwitch]; [self enableOswForNativeTouchSwitchFlipped:self.enableOswForNativeTouchSwitch];
// init CustomOSC stuff
/* sets a reference to the correct 'LayoutOnScreenControlsViewController' depending on whether the user is on an iPhone or iPad */
// self.layoutOnScreenControlsVC = [[LayoutOnScreenControlsViewController alloc] init];
BOOL isIPhone = ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPhone);
if (isIPhone) {
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"iPhone" bundle:nil];
self.layoutOnScreenControlsVC = [storyboard instantiateViewControllerWithIdentifier:@"LayoutOnScreenControlsViewController"];
}
else {
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"iPad" bundle:nil];
self.layoutOnScreenControlsVC = [storyboard instantiateViewControllerWithIdentifier:@"LayoutOnScreenControlsViewController"];
self.layoutOnScreenControlsVC.modalPresentationStyle = UIModalPresentationFullScreen;
}
[self.externalDisplayModeSelector setSelectedSegmentIndex:currentSettings.externalDisplayMode.integerValue]; [self.externalDisplayModeSelector setSelectedSegmentIndex:currentSettings.externalDisplayMode.integerValue];
[self.localMousePointerModeSelector setSelectedSegmentIndex:currentSettings.localMousePointerMode.integerValue]; [self.localMousePointerModeSelector setSelectedSegmentIndex:currentSettings.localMousePointerMode.integerValue];
@@ -1638,6 +1623,20 @@ BOOL isCustomResolution(CGSize res) {
} }
- (void)invokeOscLayout{ - (void)invokeOscLayout{
// init CustomOSC stuff
/* sets a reference to the correct 'LayoutOnScreenControlsViewController' depending on whether the user is on an iPhone or iPad */
// self.layoutOnScreenControlsVC = [[LayoutOnScreenControlsViewController alloc] init];
BOOL isIPhone = ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPhone);
if (isIPhone) {
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"iPhone" bundle:nil];
self.layoutOnScreenControlsVC = [storyboard instantiateViewControllerWithIdentifier:@"LayoutOnScreenControlsViewController"];
}
else {
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"iPad" bundle:nil];
self.layoutOnScreenControlsVC = [storyboard instantiateViewControllerWithIdentifier:@"LayoutOnScreenControlsViewController"];
self.layoutOnScreenControlsVC.modalPresentationStyle = UIModalPresentationFullScreen;
}
self.layoutOnScreenControlsVC.view.backgroundColor = [UIColor colorWithWhite:0.55 alpha:1.0]; self.layoutOnScreenControlsVC.view.backgroundColor = [UIColor colorWithWhite:0.55 alpha:1.0];
[self presentViewController:self.layoutOnScreenControlsVC animated:YES completion:nil]; [self presentViewController:self.layoutOnScreenControlsVC animated:YES completion:nil];
} }
@@ -60,6 +60,7 @@
UIScrollView *_scrollView; UIScrollView *_scrollView;
BOOL _userIsInteracting; BOOL _userIsInteracting;
bool viewJustLoaded; bool viewJustLoaded;
bool viewIsBeingResized;
CGSize _keyboardSize; CGSize _keyboardSize;
UIWindow *_extWindow; UIWindow *_extWindow;
UIView *_streamVideoRenderView; UIView *_streamVideoRenderView;
@@ -314,7 +315,8 @@
_settings = [[[DataManager alloc] init] getSettings]; //StreamFrameViewController retrieve the settings here. _settings = [[[DataManager alloc] init] getSettings]; //StreamFrameViewController retrieve the settings here.
overlayLevel = _settings.statsOverlayLevel.intValue; overlayLevel = _settings.statsOverlayLevel.intValue;
[self configOscLayoutTool]; if(viewIsBeingResized) viewIsBeingResized = false;
else [self configOscLayoutTool];
[self updateToolboxSpecialEntries]; [self updateToolboxSpecialEntries];
[self configGestures]; [self configGestures];
[self configZoomGestureAndAddStreamView]; [self configZoomGestureAndAddStreamView];
@@ -491,6 +493,7 @@
- (void)viewDidLoad - (void)viewDidLoad
{ {
viewJustLoaded = true; viewJustLoaded = true;
viewIsBeingResized = false;
[super viewDidLoad]; [super viewDidLoad];
[self.navigationController setNavigationBarHidden:YES animated:YES]; [self.navigationController setNavigationBarHidden:YES animated:YES];
@@ -869,6 +872,7 @@
} }
- (void) handleViewResize{ - (void) handleViewResize{
viewIsBeingResized = true;
_streamView.bounds = _deviceWindow.bounds; _streamView.bounds = _deviceWindow.bounds;
_streamView.frame = _deviceWindow.frame; _streamView.frame = _deviceWindow.frame;
if(![self isAirPlaying]){ if(![self isAirPlaying]){