Skip to content

Instantly share code, notes, and snippets.

@khanhduytran0
Last active August 13, 2024 05:28
Show Gist options
  • Save khanhduytran0/e5fedf77c970464faff4660164518dba to your computer and use it in GitHub Desktop.
Save khanhduytran0/e5fedf77c970464faff4660164518dba to your computer and use it in GitHub Desktop.
Allow Dynamic Island to rotate upside down
@import UIKit;
@interface UIWindow()
- (void)setAutorotates:(BOOL)autorotates forceUpdateInterfaceOrientation:(BOOL)force;
@end
@interface SBSystemApertureWindow : UIWindow
@end
// SBSystemApertureWindow has a hidden override to always set autorotates to false, we must call super
@implementation SBSystemApertureWindow(hook)
- (void)setAutorotates:(BOOL)autorotates forceUpdateInterfaceOrientation:(BOOL)force {
[super setAutorotates:YES forceUpdateInterfaceOrientation:force];
}
@end
// prevent content from flipping upside down
// FIXME: sometimes switching from landscape to portrait upside down will still leave it upside down for a short while
%hook SBSystemApertureController
- (void)_applyOrientation:(UIInterfaceOrientation)orientation withPreviousOrientation:(UIInterfaceOrientation)prevOrientation animationSettings:(id)settings {
UIView *apertureView = MSHookIvar<UIViewController *>(self, "_systemApertureViewController").view;
CGRect frame = apertureView.frame;
if (orientation == UIInterfaceOrientationPortraitUpsideDown) {
orientation = UIInterfaceOrientationPortrait;
// put your code here to reset y offset, for example:
frame = CGRectMake(0, -7, apertureView.frame.size.width, apertureView.frame.size.height);
} else if (orientation == UIInterfaceOrientationPortrait) {
// put your code here to set y offset, for example:
frame = CGRectMake(0, 20, apertureView.frame.size.width, apertureView.frame.size.height);
}
[UIView animateWithDuration:1 animations:^{
apertureView.frame = frame;
}];
%orig;
}
%end
// allow upside down
%hook SBSystemApertureCaptureVisibilityShimViewController
- (UIInterfaceOrientationMask)__supportedInterfaceOrientations {
// use all to allow landscape island, although it's still hidden
return //UIInterfaceOrientationMaskAll;
UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskPortraitUpsideDown;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(NSInteger)orientation {
return YES;
}
%end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment