2012-05-09 13 views
6

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:

Okay case

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)); 

Whoa case

... non sembra più così bello. Più 10 punti:

CGPathAddRect(shadowPath, NULL, CGRectMake(4, 0, 130, 48)); 
CGPathAddRect(shadowPath, NULL, CGRectMake(120, 50, 116, 48)); 

WTF case

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?

risposta

3

Sì, sembra un bug. Anche se non lo è, presentando un bug report Apple dovrebbe rispondere e darti informazioni utili.

+0

Sì, ** sicuramente ** file un rapporto. Molto probabilmente gli ingegneri Apple non scopriranno questo tipo di cose se non li informiamo. –

+0

@ DavidRönnqvist potrebbe essere stato un errore da parte mia, non volevo sollevare un falso allarme. – zrxq

+0

Cinque mesi dopo: niente. – zrxq