Created
September 24, 2023 04:02
-
-
Save pookjw/0612cfcfff50c0f5a4d243e632741dea to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// UIWindowScene+interfaceOrientationDidChangeNotification.h | |
#import <UIKit/UIKit.h> | |
NS_HEADER_AUDIT_BEGIN(nullability, sendability) | |
static NSNotificationName const UIWindowSceneInterfaceOrientationDidChangeNotification = @"UIWindowSceneInterfaceOrientationDidChangeNotification"; | |
static NSString * const UIWindowSceneInterfaceOrientationValueUserInfoKey = @"UIWindowSceneInterfaceOrientationValueUserInfoKey"; | |
static NSString * const UIWindowSceneInterfaceOrientationAnimationDurationUserInfoKey = @"UIWindowSceneInterfaceOrientationAnimationDurationUserInfoKey"; | |
NS_HEADER_AUDIT_END(nullability, sendability) | |
// UIWindowScene+interfaceOrientationDidChangeNotification.mm | |
#import "UIWindowScene+interfaceOrientationDidChangeNotification.h" | |
#import <objc/runtime.h> | |
#import <objc/message.h> | |
namespace UIWindowScene_Booth_Category { | |
namespace _updateClientSettingsToInterfaceOrientation_withAnimationDuration { | |
static void (*original)(UIWindowScene *self, SEL _cmd, UIInterfaceOrientation interfaceOrientation, CGFloat animationDuration); | |
static void custom(UIWindowScene *self, SEL _cmd, UIInterfaceOrientation interfaceOrientation, CGFloat animationDuration) { | |
original(self, _cmd, interfaceOrientation, animationDuration); | |
[NSNotificationCenter.defaultCenter postNotificationName:UIWindowSceneInterfaceOrientationDidChangeNotification | |
object:self | |
userInfo:@{ | |
UIWindowSceneInterfaceOrientationValueUserInfoKey: @(self.interfaceOrientation), | |
UIWindowSceneInterfaceOrientationAnimationDurationUserInfoKey: @(animationDuration) | |
}]; | |
} | |
static void swizzle() { | |
Method method = class_getInstanceMethod(UIWindowScene.class, NSSelectorFromString(@"_updateClientSettingsToInterfaceOrientation:withAnimationDuration:")); | |
original = reinterpret_cast<void (*)(UIWindowScene *, SEL, UIInterfaceOrientation, CGFloat)>(method_getImplementation(method)); | |
method_setImplementation(method, reinterpret_cast<IMP>(&custom)); | |
} | |
} | |
} | |
@implementation UIWindowScene (Booth_Category) | |
+ (void)load { | |
UIWindowScene_Booth_Category::_updateClientSettingsToInterfaceOrientation_withAnimationDuration::swizzle(); | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example