0

I have a custom view in which I want to display a CALayer with PDF content. To do so I implemented a delegate NSObject subclass as shown in the first answer to Using CALayer Delegate.


Since I have a document-based app, I have a starting window from which I can open documents. From the custom document I initWithWindowNibName: a custom windowController from the makeWindowControllers method. From the windowController, in windowDidLoad, I set a custom NSView's variable values and initialize the CALayer. In the same place I run this line of code to draw the content:

[[[PDFViewLayerDelegate alloc] initWithUrl:url andPageIndex:currentPageIndex] drawLayer:layer1 inContext:[[NSGraphicsContext currentContext] graphicsPort]];

What happens is: while before running that line the background of the CALayer was set to green and would appear only in the correct window, now the PDF content is drawn to the initial window only while both layers are filled with white (which is also done in the delegate method).

My questions are:

  • Why is my CALayer being drawn to a view which is not of the custom NSView subclass which creates it? and furthermore in different windows?
  • Are both views in each window sharing the same graphicsContext? This might be the cause..
Community
  • 1
  • 1
BigCola
  • 312
  • 1
  • 4
  • 16

1 Answers1

0

I understood the problem... As I presumed the problem was both windows share the same graphicsContext, as the currentContext is:

"The current graphics context of the current thread."


I simply resolved this problem placing the CALayer drawing function call inside the drawRect: method of it's container NSView since drawRect: is responsible for drawing exclusively inside it's view and probably already handles the graphicsContext stuff in somewhat way.

BigCola
  • 312
  • 1
  • 4
  • 16