小编zrs*_*slv的帖子

CALayer的shadowPath中的错误?

我正在尝试使用以下方法绘制自定义形状的阴影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];
} …
Run Code Online (Sandbox Code Playgroud)

cocoa core-animation core-graphics calayer

6
推荐指数
1
解决办法
648
查看次数

标签 统计

calayer ×1

cocoa ×1

core-animation ×1

core-graphics ×1