Devs, I have a NSScrollview with and NSImageView as its document view. I have a sublayer for the scrollview that serves my selection rect. When I load an image I can pressed down and draw the selection rect, but as soon as I resize the window, the rect disappears but the image remains. As the window resizes, the code changes the location of the image in the window and should also be updating the location of the selection rect such that the selection rect “stays in place” with respect to the image as its location is updated due to the window resize. Here is what I have in drawRect():
-(void)drawRect:(NSRect)dirtyRect { if(([self inLiveResize] == YES) && (_userImage != nil)) { // grab the previous image location CGPoint prevImageLocation = _imageLocation; // compute frame origin CGRect documentViewFrame; documentViewFrame.origin.x = 0.0; documentViewFrame.origin.y = 0.0; // if the content view is larger than the image if([[self contentView] frame].size.width > [_userImage size].width) { documentViewFrame.size.width = [[self contentView] frame].size.width; _imageLocation.x = ( documentViewFrame.size.width - [_userImage size].width ) / 2.0; } else { documentViewFrame.size.width = [_userImage size].width; _imageLocation.x = 0.0; } if([[self contentView] frame].size.height > [_userImage size].height) { documentViewFrame.size.height = [[self contentView] frame].size.height; _imageLocation.y = ( documentViewFrame.size.height - [_userImage size].height ) / 2.0; } else { documentViewFrame.size.height = [_userImage size].height; _imageLocation.y = 0.0; } [[self documentView] setFrame:documentViewFrame]; // compute new location for selection layer [CATransaction begin]; [CATransaction setDisableActions:YES]; _selectionFrame.origin.x += ( _imageLocation.x - prevImageLocation.x ); _selectionFrame.origin.y += ( _imageLocation.y - prevImageLocation.y ); [_selectionLayer setFrame:_selectionFrame]; [CATransaction commit]; } } _______________________________________________ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com