0

The Core Animation Programming Guide led me to believe that a sublayer could, by default, extend outside the bounds of a host view without being clipped. But that's not what's happening for me.

Here's how I initialize my layer-hosting custom view:

- (id)initWithFrame:(NSRect)frame
{
    self = [super initWithFrame:frame];
    if (self != nil) {
        mBaseImage = [[NSImage imageNamed: @"Button.png"] retain];
        mSliderImage = [[NSImage imageNamed: @"Track.png"] retain];

        mRootLayer = [CALayer layer];
        mRootLayer.masksToBounds = NO;
        [self setLayer: mRootLayer ];
        [self setWantsLayer: YES];
        mRootLayer.contents = mBaseImage;

        mSliderLayer = [CALayer layer];
        [mRootLayer addSublayer: mSliderLayer];
        NSSize imSize = [mSliderImage size];
        NSRect sliderBounds = NSMakeRect( 0.0f, 0.0f, imSize.width, imSize.height );
        mSliderLayer.bounds = sliderBounds;
        mSliderLayer.contents = mSliderImage;
        mSliderLayer.position = NSMakePoint( 31.0f, 31.0f );
    }

    return self;
}

The host view, and the image used as its contents, are 62x62, while the sublayer image is 90x10. But the whole thing gets clipped to the 62x62 bounds. What am I missing?

4

1 回答 1

5

诀窍似乎是视图必须包含在另一个具有层的视图(可能是窗口的内容视图)中。(有记录吗?)

于 2013-10-09T21:00:48.683 回答