Need a way to make PKInkingTool width constant

Originator:uson1x
Number:rdar://FB8013221 Date Originated:
Status:Open Resolved:
Product:PencilKit Product Version:iOS 14
Classification:Suggestion Reproducible:
 
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, the drawings would look different on our other platforms, like Web-app.

It would be nice if there was a way to make width of PKInkingTool constant.

I tried swizzling methods like defaultWidthForInkType:, but my swizzled methods are never called.

Example of code below:
@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

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!