Add support to change app size

This commit is contained in:
xzzpig
2024-11-18 20:46:44 +08:00
parent 0f5e644041
commit 978c50c271
4 changed files with 34 additions and 9 deletions
@@ -1151,6 +1151,11 @@ static NSMutableSet* hostList;
[self swapResolutionWidthHeightAccordingly];
}
- (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator {
[super viewWillTransitionToSize:size withTransitionCoordinator:coordinator];
[self handleOrientationChange];
}
-(void)handleRealOrientationChange{
@@ -1194,14 +1199,25 @@ static NSMutableSet* hostList;
}
-(void)swapResolutionWidthHeightAccordingly{
-(void) swapResolutionWidthHeightAccordingly {
DataManager* dataMan = [[DataManager alloc] init];
Settings *currentSettings = [dataMan retrieveSettings];
CGFloat screenWidthInPoints = CGRectGetWidth([[UIScreen mainScreen] bounds]);
CGFloat screenHeightInPoints = CGRectGetHeight([[UIScreen mainScreen] bounds]);
bool needSwap = ((currentSettings.width.floatValue - currentSettings.height.floatValue) * (screenWidthInPoints - screenHeightInPoints)) < 0; //update the current resolution accordingly
NSLog(@"need to swap width & height: %d", needSwap);
if(needSwap){
UIWindow *window = UIApplication.sharedApplication.windows.firstObject;
CGFloat screenScale = window.screen.scale;
CGFloat screenWidthInPoints = CGRectGetWidth(window.frame);
CGFloat screenHeightInPoints = CGRectGetHeight(window.frame);
CGFloat fullScreenWidth = screenWidthInPoints * screenScale;
CGFloat fullScreenHeight = screenHeightInPoints * screenScale;
bool needSwap = ((currentSettings.width.floatValue - currentSettings.height.floatValue) *
(fullScreenWidth - fullScreenHeight)) < 0;
NSLog(@"Current screen size: %.0f x %.0f", fullScreenWidth, fullScreenHeight);
NSLog(@"Current setting size: %.0f x %.0f", currentSettings.width.floatValue, currentSettings.height.floatValue);
NSLog(@"Need to swap width & height: %d", needSwap);
if(needSwap) {
CGFloat tmpLength = currentSettings.width.floatValue;
currentSettings.width = @(currentSettings.height.floatValue);
currentSettings.height = @(tmpLength);
@@ -1209,7 +1225,6 @@ static NSMutableSet* hostList;
}
}
#if TARGET_OS_TV
-(void)handleCollectionViewLongPress:(UILongPressGestureRecognizer *)gestureRecognizer
{