Add support to change app size

This commit is contained in:
xzzpig committed 2024-11-18 20:46:44 +08:00
1 parent 0f5e644041
commit 978c50c271
4 files changed
+34 -9

No files matched your search

-2
View File
@@ -73,8 +73,6 @@
<array> <array>
<string>armv7</string> <string>armv7</string>
</array> </array>
<key>UIRequiresFullScreen</key>
<true/>
<key>UIStatusBarHidden</key> <key>UIStatusBarHidden</key>
<true/> <true/>
<key>UISupportedInterfaceOrientations</key> <key>UISupportedInterfaceOrientations</key>
@@ -1151,6 +1151,11 @@ static NSMutableSet* hostList;
[self swapResolutionWidthHeightAccordingly]; [self swapResolutionWidthHeightAccordingly];
} }
- (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator {
[super viewWillTransitionToSize:size withTransitionCoordinator:coordinator];
[self handleOrientationChange];
}
-(void)handleRealOrientationChange{ -(void)handleRealOrientationChange{
@@ -1194,14 +1199,25 @@ static NSMutableSet* hostList;
} }
-(void)swapResolutionWidthHeightAccordingly{ -(void) swapResolutionWidthHeightAccordingly {
DataManager* dataMan = [[DataManager alloc] init]; DataManager* dataMan = [[DataManager alloc] init];
Settings *currentSettings = [dataMan retrieveSettings]; Settings *currentSettings = [dataMan retrieveSettings];
CGFloat screenWidthInPoints = CGRectGetWidth([[UIScreen mainScreen] bounds]);
CGFloat screenHeightInPoints = CGRectGetHeight([[UIScreen mainScreen] bounds]); UIWindow *window = UIApplication.sharedApplication.windows.firstObject;
bool needSwap = ((currentSettings.width.floatValue - currentSettings.height.floatValue) * (screenWidthInPoints - screenHeightInPoints)) < 0; //update the current resolution accordingly CGFloat screenScale = window.screen.scale;
NSLog(@"need to swap width & height: %d", needSwap); CGFloat screenWidthInPoints = CGRectGetWidth(window.frame);
if(needSwap){ 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; CGFloat tmpLength = currentSettings.width.floatValue;
currentSettings.width = @(currentSettings.height.floatValue); currentSettings.width = @(currentSettings.height.floatValue);
currentSettings.height = @(tmpLength); currentSettings.height = @(tmpLength);
@@ -1209,7 +1225,6 @@ static NSMutableSet* hostList;
} }
} }
#if TARGET_OS_TV #if TARGET_OS_TV
-(void)handleCollectionViewLongPress:(UILongPressGestureRecognizer *)gestureRecognizer -(void)handleCollectionViewLongPress:(UILongPressGestureRecognizer *)gestureRecognizer
{ {
@@ -1073,5 +1073,10 @@ BOOL isCustomResolution(CGSize res) {
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
} }
- (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator {
[super viewWillTransitionToSize:size withTransitionCoordinator:coordinator];
[self deviceOrientationDidChange];
}
@end @end
@@ -860,4 +860,11 @@
} }
#endif #endif
- (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator {
[super viewWillTransitionToSize:size withTransitionCoordinator:coordinator];
Log(LOG_I, @"View size changed, terminating stream");
[self returnToMainFrame];
}
@end @end