小编jli*_*ink的帖子

相当于Mac的clipToBounds(NSView的图层)

我有一个类"GlobalView",它扩展了NSView,并有两个子视图GreenRectView(扩展了NSView).我使用我的GreenRectView中的CALayer,以便能够围绕默认左下角以外的点旋转(使用setAffineTransform :)我的视图.因此我使用了"setAnchorPoint".一切都很好,除了当我的绿色矩形旋转时,它不会超出其视图的范围.在iOS中,可以使用clipToBounds:NO来接受绘图显示在边界外但在Mac中它不适用于masksToBounds ...如何旋转我的greenrect并完全显示它无论旋转角度.

见图: 截图

在此输入图像描述 以下是代码:

    @implementation GlobalView
- (id)initWithFrame:(NSRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code here.
        g = [[GreenRectView alloc]initWithPoint:NSMakePoint(200, 200)];
        [self addSubview:g];

        g = [[GreenRectView alloc]initWithPoint:NSMakePoint(100, 400)];
        [self addSubview:g];    
    }
    return self;
}

#import <Quartz/Quartz.h>
#include <ApplicationServices/ApplicationServices.h>

@implementation GreenRectView

- (id)initWithFrame:(NSRect)frame {
    self = [super initWithFrame:frame];
    if (self) {     
        [self setWantsLayer:YES];
        layer = [self layer];

        [self setLayer:layer];
        [layer setAnchorPoint:NSMakePoint(0.0,0.5)];
        [layer setMasksToBounds:NO];

        [menuLayer addSublayer:layer];

    }
    return self;
}

- (id)initWithPoint:(CGPoint)p {
    return [self initWithFrame:NSMakeRect(p.x, p.y, …
Run Code Online (Sandbox Code Playgroud)

macos calayer cliptobounds

7
推荐指数
0
解决办法
2330
查看次数

标签 统计

calayer ×1

cliptobounds ×1

macos ×1