Re: CALayer show/hide question when moving to full screen.
Re: CALayer show/hide question when moving to full screen.
- Subject: Re: CALayer show/hide question when moving to full screen.
- From: Markus Spoettl <email@hidden>
- Date: Tue, 28 Aug 2012 12:28:12 +0200
On 8/28/12 12:09 PM, Koen van der Drift wrote:
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?
Are you sure your notification is delivered? The methods do not meet the
selector requirement, which is (quoting documentation for
-addObserver:selector:name:object):
------------------------
notificationSelector
Selector that specifies the message the receiver sends notificationObserver to
notify it of the notification posting. The method specified by
notificationSelector must have one and only one argument (an instance of
NSNotification).
------------------------
So your methods should be implemented as
-(void) showTextHighlight:(NSNotification *)notification
- (void)removeTextHighlight:(NSNotification *)notification
Regards
Markus
--
__________________________________________
Markus Spoettl
_______________________________________________
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