这是我的问题的延续停的NSView-的drawRect结算前方的绘图lockfocus,不再视为工作-ON-莫哈韦 。 我用图案lockFocus图形上下文flushWindow图案绘制到另一视图。 这不再工作在MacOS 10.14,为的意见后备存储已更改(新的二进制文件)。
的NSView有一个方法makeBackingLayer是不是有没出息,我猜。 下面的代码片段已经makeBackingLayer叫了,我可以把它用我的CALayer子类“TransparentLayer”,成功。 成功至今,我的子类的drawInContext:确实叫,因为它应该,setNeedsDisplay被称为层后。 但是,任何图纸我似乎不存在。 我究竟做错了什么? (ScreenRect是全屏RECT)。
我的NSView(全屏):
- (id)initWithFrame:(NSRect)frame
{
ALog(@"");
self = [super initWithFrame:frame];
if (self) {
self.wantsLayer = YES;
}
return self;
}
- (BOOL) isOpaque { return NO; }
- (BOOL) wantsLayer { return YES; } // YES for layers, else drawRect
- (BOOL) wantsUpdateLayer { return YES; }
- (CALayer *)makeBackingLayer
// NB: If self.layer is already set, makeBackingLayer is NOT called
{
ALog(@"");
// OWN LAYER TYPE (simply subclass of CALayer)
TransparentLayer *newLayer = [[TransparentLayer alloc] initWithFrame:ScreenRect];
return newLayer;
}
- (void)updateLayer { ALog(@"(we do not want this)"); } // (not called)
- (void)drawInContext:(CGContextRef)ctx { ALog( @"ctx=%p",ctx ); } // (not called)
- (void)drawLayer:(CALayer *)layer inContext:(CGContextRef)ctx { ALog( @"layer=%p ctx=%p",layer,ctx ); } // (not called)
- (void)drawRect:(NSRect)dirtyRect { ALog(@""); } // (not called)
TransparentLayer(全屏,太):
- (id)initWithFrame:(NSRect)frame
{
ALog(@"");
self = [super init];
if (self) {
self.bounds = frame; // ?
self.frame = frame; // ?
self.contentsRect = frame;
self.backgroundColor = [NSColor clearColor].CGColor; // transparent
self.opaque = NO;
}
return self;
}
- (void)updateLayer
{
ALog(@"");
}
- (void)_OUT_display
// THIS (display) IS CALLED when this method is present, else drawInContext:
{
ALog(@"");
}
- (void)drawInContext:(CGContextRef)ctx
// THIS IS CALLED, BUT NO OUTPUT VISIBLE ON SCREEN
// ViewController calls every cycle: [self.stillView.layer setNeedsDisplay];
{
ALog(@"");
// Draw a BLUE square 50x50, screen bottom, left
CGRect R = CGRectMake(0., 0., 50., 50. );
CGContextSetRGBFillColor(ctx, 0,0,1, 1); // BLUE
CGContextFillRect(ctx, R);
}