Post

Replies

Boosts

Views

Activity

How to make PKInkingTool width constant?
We want to use new iOS 14 PencilKit vector capabilities in our app. However, our current drawing component is always fixed-width. If we use dynamic brush width, like PencilKit has, it will look different on our other platforms. Is there a way to make PKInkingTool having fixed width? I tried swizzling methods like defaultWidthForInkType:, but my swizzled methods are never called. @implementation PKInkingTool (Tracking) (void)load {     [super load];     static dispatch_once_t onceToken;     dispatch_once(&onceToken, ^{         const char *className = [NSStringFromClass(self) UTF8String];         Class class = objc_getMetaClass(className);         SEL originalSelector = @selector(defaultWidthForInkType:);         SEL swizzledSelector = @selector(ed_defaultWidthForInkType:);         Method originalMethod = class_getClassMethod(class, originalSelector);         Method swizzledMethod = class_getClassMethod(class, swizzledSelector);         BOOL didAddMethod =             class_addMethod(class,                 originalSelector,                 method_getImplementation(swizzledMethod),                 method_getTypeEncoding(swizzledMethod));         if (didAddMethod) {             class_replaceMethod(class,                 swizzledSelector,                 method_getImplementation(originalMethod),                 method_getTypeEncoding(originalMethod));         } else {             method_exchangeImplementations(originalMethod, swizzledMethod);         } } (CGFloat)ed_defaultWidthForInkType:(PKInkType)inkType {     return 15.0; } @end
1
0
1.3k
Sep ’21
How to make PKInkingTool width constant?
We want to use new iOS 14 PencilKit vector capabilities in our app. However, our current drawing component is always fixed-width. If we use dynamic brush width, like PencilKit has, it will look different on our other platforms. Is there a way to make PKInkingTool having fixed width? I tried swizzling methods like defaultWidthForInkType:, but my swizzled methods are never called. @implementation PKInkingTool (Tracking) (void)load {     [super load];     static dispatch_once_t onceToken;     dispatch_once(&onceToken, ^{         const char *className = [NSStringFromClass(self) UTF8String];         Class class = objc_getMetaClass(className);         SEL originalSelector = @selector(defaultWidthForInkType:);         SEL swizzledSelector = @selector(ed_defaultWidthForInkType:);         Method originalMethod = class_getClassMethod(class, originalSelector);         Method swizzledMethod = class_getClassMethod(class, swizzledSelector);         BOOL didAddMethod =             class_addMethod(class,                 originalSelector,                 method_getImplementation(swizzledMethod),                 method_getTypeEncoding(swizzledMethod));         if (didAddMethod) {             class_replaceMethod(class,                 swizzledSelector,                 method_getImplementation(originalMethod),                 method_getTypeEncoding(originalMethod));         } else {             method_exchangeImplementations(originalMethod, swizzledMethod);         } } (CGFloat)ed_defaultWidthForInkType:(PKInkType)inkType {     return 15.0; } @end
Replies
1
Boosts
0
Views
1.3k
Activity
Sep ’21