Skip to content

Instantly share code, notes, and snippets.

@stefanceriu
Last active January 17, 2022 15:10
Show Gist options
  • Star 11 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stefanceriu/3c21452b7d481ceae41c0ca5f0f5c15d to your computer and use it in GitHub Desktop.
Save stefanceriu/3c21452b7d481ceae41c0ca5f0f5c15d to your computer and use it in GitHub Desktop.
Disable Mac Catalyst 77% app scaling
//
// UINSSceneView+CTX.h
// EFClass
//
// Created by Stefan Ceriu on 28/11/2019.
// Copyright © 2019 EF Education First. All rights reserved.
//
#import <Foundation/Foundation.h>
@interface NSObject (CTX)
@end
//
// UINSSceneView+CTX.m
// EFClass
//
// Created by Stefan Ceriu on 28/11/2019.
// Copyright © 2019 EF Education First. All rights reserved.
//
#import "UINSSceneView+CTX.h"
#import <objc/runtime.h>
@implementation NSObject (CTX)
+ (void)load
{
#if TARGET_OS_MACCATALYST
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
CTXSwizzleInstanceMethod(objc_getClass("UINSSceneView"), NSSelectorFromString(@"scaleFactor"), @selector(ctx_scaleFactor));
});
#endif
}
- (CGFloat)ctx_scaleFactor
{
return 1.0f;
}
static void CTXSwizzleInstanceMethod(Class class, SEL originalSelector, SEL swizzledSelector) {
Method originalMethod = class_getInstanceMethod(class, originalSelector);
Method swizzledMethod = class_getInstanceMethod(class, swizzledSelector);
if (class_addMethod(class, originalSelector, method_getImplementation(swizzledMethod), method_getTypeEncoding(swizzledMethod))) {
class_replaceMethod(class, swizzledSelector, method_getImplementation(originalMethod), method_getTypeEncoding(originalMethod));
} else {
method_exchangeImplementations(originalMethod, swizzledMethod);
}
}
@end
@chenshengzhi
Copy link

Thank you very much. Follow you. -_-

@exotexot
Copy link

exotexot commented Oct 8, 2020

Hello! Building a macos app using react-native for ios + Catalyst and I'm wondering how to implement this fix. Any chances to get support on how this fix is being applied?

@stefanceriu
Copy link
Author

Hey, normally you would just drop it into your project but I don’t know how that works in react native.

@dvkch
Copy link

dvkch commented Apr 28, 2021

This seems to have stopped working on macOS 11.3, anyone can confirm?

@Neil20170220
Copy link

not work on macOS 11.3

@JunyuKuang
Copy link

macOS 11.3 has different APIs. I have made my implementation public: OverrideCatalystScaleFactor.swift

@stefanceriu
Copy link
Author

Nice! 👌

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment