che sto cercando di disegnare un'ombra a forma di personalizzato utilizzando CALayer
:Bug in shadowPath di CALayer?
#import <QuartzCore/QuartzCore.h>
@implementation ZKSBAppDelegate
@synthesize window = _window;
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
NSView *view = self.window.contentView;
view.wantsLayer = YES;
CALayer *shadowLayer = [CALayer layer];
shadowLayer.shadowOpacity = 1;
shadowLayer.shadowRadius = 1;
shadowLayer.shadowOffset = NSMakeSize(0, 0);
CGMutablePathRef shadowPath = CGPathCreateMutable();
// setting the following rect's width to 100 fixes everything.
// setting it to 130 screws the shadow even more.
CGPathAddRect(shadowPath, NULL, CGRectMake(4, 0, 120, 48));
CGPathAddRect(shadowPath, NULL, CGRectMake(120, 50, 116, 48));
shadowLayer.shadowPath = shadowPath;
CGPathRelease(shadowPath);
[view.layer addSublayer:shadowLayer];
}
@end
È possibile creare un progetto di cacao vuoto in Xcode, sostituire il contenuto del file .m del vostro app.delegate con il codice di cui sopra e provarlo voi stessi .
Sembra che la specifica geometria del percorso d'ombra causi l'imprevisto di CALayer
.
Ad esempio:
CGPathAddRect(shadowPath, NULL, CGRectMake(4, 0, 100, 48));
CGPathAddRect(shadowPath, NULL, CGRectMake(120, 50, 116, 48));
Questo sembra perfettamente a posto:
Ora sto andando a fare il primo rettangolo più ampio di 20 punti:
CGPathAddRect(shadowPath, NULL, CGRectMake(4, 0, 120, 48));
CGPathAddRect(shadowPath, NULL, CGRectMake(120, 50, 116, 48));
... non sembra più così bello. Più 10 punti:
CGPathAddRect(shadowPath, NULL, CGRectMake(4, 0, 130, 48));
CGPathAddRect(shadowPath, NULL, CGRectMake(120, 50, 116, 48));
Ora che è sbagliato pianura, non è vero?
Quindi, la domanda è: che diavolo sta succedendo, sto sbagliando o qualcosa del genere? Pensi che sia un bug e dovrei presentare un rapporto?
Sì, ** sicuramente ** file un rapporto. Molto probabilmente gli ingegneri Apple non scopriranno questo tipo di cose se non li informiamo. –
@ DavidRönnqvist potrebbe essere stato un errore da parte mia, non volevo sollevare un falso allarme. – zrxq
Cinque mesi dopo: niente. – zrxq