• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
CALayer show/hide question when moving to full screen.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

CALayer show/hide question when moving to full screen.


  • Subject: CALayer show/hide question when moving to full screen.
  • From: Koen van der Drift <email@hidden>
  • Date: Tue, 28 Aug 2012 06:09:28 -0400

As discussed in another thread last week, I am using CALayers to add custom text highlighting in an NSTextView.  Briefly, based on the user input I get a range of text, get the rect(s) of the text and calculate the CALayer(s).

Now when the user resizes the window, of course the CALayers need to move along with the text. Since the text can move, e.g. to another line, the relative positions of the CALayers with respect to the window change too, so I cannot just do a simple transform to the end point.

So I decided to remove the CALayer(s) when a "windowWillResize" notification is received, and recalculate and redraw them when the "windowDidResize" notification is received:

    [nc addObserver: self selector: @selector(removeTextHighlight:) name: NSWindowWillStartLiveResizeNotification object: nil];
    [nc addObserver: self selector: @selector(showTextHighlight:) name: NSWindowDidEndLiveResizeNotification object: nil];


-(void) showTextHighlight
{
	[self createHighlightLayer];
	[self.layer addSublayer: self.highlightLayer];
}

- (void) removeTextHighlight
{
    self.highlightLayer.sublayers = nil;
}

This works fine for the window resizing. Of course when the user goes to full screen, I need to do the same, so I added some more notifications:

    [nc addObserver: self selector: @selector(removeTextHighlight:) name: NSWindowWillEnterFullScreenNotification object: nil];
    [nc addObserver: self selector: @selector(showTextHighlight:) name: NSWindowDidEnterFullScreenNotification object: nil];

    [nc addObserver: self selector: @selector(removeTextHighlight:) name: NSWindowWillExitFullScreenNotification object: nil];
    [nc addObserver: self selector: @selector(showTextHighlight:) name: NSWindowDidExitFullScreenNotification object: nil];

What happens now is that when the user goes to full screen the highlight disappears, then the window reaches the full screen and I briefly see an 'echo image' of the text highlight in its original position, before it shows the new ones.

What is going on here, maybe the CALayers are cached somewhere?

- Koen.


_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: CALayer show/hide question when moving to full screen.
      • From: Markus Spoettl <email@hidden>
  • Prev by Date: On slow PNG image display in MapKit with iOS 5.1.x
  • Next by Date: Re: CALayer show/hide question when moving to full screen.
  • Previous by thread: On slow PNG image display in MapKit with iOS 5.1.x
  • Next by thread: Re: CALayer show/hide question when moving to full screen.
  • Index(es):
    • Date
    • Thread