CGContextSetShadow () - trend change between iOS 3.0 and 4.0?

I used CGContextSetShadowWithColor()Quartz on my iPhone in my code to generate a “stomped” search for text and other things (in drawRect:and drawLayer:inContext:).

It worked fine, but when running the same code with iOS 3.2 and now iOS 4.0, I noticed that the shadows are all in the opposite direction. For instance. in the following code, I set the black shadow 1 pixel above the text, which gave it a “pressed” look, and now this shadow is 1px lower than the text, giving it a standard shadow.

...
CGContextSetShadowWithColor(context, CGSizeMake(0.f, 1.f), 0.5f, shadowColor);
CGContextShowGlyphsAtPoint(context, origin.x, origin.y, glyphs, length);
...

Now I do not know if I (or was) something wrong, or whether the attitude to this setting has changed. I did not apply any transformations that could explain this to me, at least not consciously. I flipped the text matrix in one instance, but not in the other, and this behavior is consistent. Plus, I couldn't find anything about this in the SDK release notes, so it seems like it's possible. What could be the problem?

+5
source share
3 answers

, , Apple; , , UIView. Y, iOS 3.2+, iOS < 3.2 , 1 -1, :

...
CGContextSetShadowWithColor(context, CGSizeMake(0.f, [UIView shadowVerticalMultiplier] * -1.f), 0.5f, textShadowColor);
...

:

@interface UIView (shadowBug) 

+ (NSInteger) shadowVerticalMultiplier;    

@end


@implementation UIView (shadowBug)

+ (NSInteger) shadowVerticalMultiplier
{
    static NSInteger shadowVerticalMultiplier = 0;
    if (0 == shadowVerticalMultiplier) {
        CGFloat systemVersion = [[[UIDevice currentDevice] systemVersion] floatValue];
        shadowVerticalMultiplier = (systemVersion < 3.2f) ? -1 : 1;
    }

    return shadowVerticalMultiplier;
}


@end
+3

, , .:)

0

iOS 4.0 has the same change in behavior (I found my way here by searching for CGContextSetShadowwhen updating my iPhone app for 4.0). Thus, it seems to CGContextSetShadowbehave differently if you are referencing iPhone OS 3.1.3 earlier, and differently if you are referencing iPhone OS 3.2 or later.

0
source

All Articles