Last active
September 29, 2024 00:58
-
-
Save JunyuKuang/75fcb81fd6046c0bf31933d85043d04b to your computer and use it in GitHub Desktop.
Disable 77% scaling for Mac Catalyst apps. (Swift)
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
let overrideCatalystScaleFactor: Void = { | |
guard let sceneViewClass = NSClassFromString("UINSSceneView") as? NSObject.Type else { | |
return | |
} | |
if sceneViewClass.instancesRespond(to: NSSelectorFromString("scaleFactor")) { | |
// old | |
swizzleInstanceMethod( | |
class: sceneViewClass, | |
originalSelector: NSSelectorFromString("scaleFactor"), | |
swizzledSelector: #selector(swizzle_scaleFactor) | |
) | |
} else { | |
// macOS 11.3 Beta 3+ | |
swizzleInstanceMethod( | |
class: sceneViewClass, | |
originalSelector: NSSelectorFromString("sceneToSceneViewScaleFactor"), | |
swizzledSelector: #selector(swizzle_scaleFactor) | |
) | |
swizzleInstanceMethod( | |
class: sceneViewClass, | |
originalSelector: NSSelectorFromString("fixedSceneToSceneViewScaleFactor"), | |
swizzledSelector: #selector(swizzle_scaleFactor2) | |
) | |
swizzleInstanceMethod( | |
class: NSClassFromString("UINSSceneContainerView"), | |
originalSelector: NSSelectorFromString("sceneToSceneViewScaleForLayout"), | |
swizzledSelector: #selector(swizzle_scaleFactor3) | |
) | |
} | |
}() | |
@objc private extension NSObject { | |
func swizzle_scaleFactor() -> CGFloat { 1 } | |
func swizzle_scaleFactor2() -> CGFloat { 1 } | |
func swizzle_scaleFactor3() -> CGFloat { 1 } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Running fine for years. Apple don't cares.