CGPatternDrawPatternCallback не вызывается в iOS 12 / Цель C - PullRequest
0 голосов
/ 03 октября 2018

Следующий код Objective-C работал корректно в iOS 9 - 11. Он рисует шахматную доску с цветными квадратами.По некоторым причинам обратный вызов, который добавляет цвета, не вызывается в iOS 12 и Xcode 10.0.Я пробовал множество исправлений, но ничего очевидного не сработало.Кажется, что-то изменилось в iOS 12, но ничего из того, что я пробовал, не устранило проблему.

-(id)initWithFrame:(CGRect)frame checkerSize:(CGSize)checkerSize darkColor:(UIColor *)darkShade lightColor:(UIColor *)lightShade { 
    self = [super initWithFrame:frame];
    if(self != nil)
    {
        //  Initialize the property values 
        checkerHeight = checkerSize.height;
        checkerWidth = checkerSize.width;

        self.darkColor  = darkShade;
        self.lightColor = lightShade;


        // Colored Pattern setup
        CGPatternCallbacks coloredPatternCallbacks = {0, ColoredPatternCallback, NULL};
        CGRect clippingRectangle = CGRectMake(0.0, 0.0, 2.0*checkerWidth, 2.0*checkerHeight);

        // First we need to create a CGPatternRef that specifies the qualities of our pattern.
        CGPatternRef coloredPattern = CGPatternCreate(
                                                  (__bridge_retained void *)self,       // 'info' pointer for our callback
                                                  clippingRectangle,                              // the pattern coordinate space, drawing is clipped to this rectangle
                                                  CGAffineTransformIdentity,            // a transform on the pattern coordinate space used before it is drawn.
                                                  2.0*checkerWidth, 2.0*checkerHeight,  // the spacing (horizontal, vertical) of the pattern - how far to move after drawing each cell
                                                  kCGPatternTilingNoDistortion,
                                                  true,                                 // this is a colored pattern, which means that you only specify an alpha value when drawing it
                                                  &coloredPatternCallbacks);            // the callbacks for this pattern.

        // To draw a pattern, you need a pattern colorspace.
        // Since this is an colored pattern, the parent colorspace is NULL, indicating that it only has an alpha value.
        CGColorSpaceRef coloredPatternColorSpace = CGColorSpaceCreatePattern(NULL);
        CGFloat alpha = 1.0;

        // Since this pattern is colored, we'll create a CGColorRef for it to make drawing it easier and more efficient.
        // From here on, the colored pattern is referenced entirely via the associated CGColorRef rather than the
        // originally created CGPatternRef.
        coloredPatternColor = CGColorCreateWithPattern(coloredPatternColorSpace, coloredPattern, &alpha);
        CGColorSpaceRelease(coloredPatternColorSpace);
        CGPatternRelease(coloredPattern);
    }
    return self;
}

void ColoredPatternCallback(void *info, CGContextRef context) {

    HS_QuartzPatternView *self = (__bridge_transfer id)info;    //  needed to access the Obj-C properties from the C function

    CGFloat checkerHeight = [self checkerHeight];
    CGFloat checkerWidth = [self checkerWidth];

    // "Dark" Color

    UIColor *dark = [self darkColor];

    CGContextSetFillColorWithColor(context, dark.CGColor);
    CGContextFillRect(context, CGRectMake(0.0, 0.0, checkerWidth, checkerHeight));
    CGContextFillRect(context, CGRectMake(checkerWidth, checkerHeight, checkerWidth, checkerHeight));

    // "Light" Color
    UIColor *light = [self lightColor];

    CGContextSetFillColorWithColor(context, light.CGColor);
    CGContextFillRect(context, CGRectMake(checkerWidth, 0.0, checkerWidth, checkerHeight));
    CGContextFillRect(context, CGRectMake(0.0, checkerHeight, checkerWidth, checkerHeight));
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...