• 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 disappears on view resize...
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

CALayer disappears on view resize...


  • Subject: CALayer disappears on view resize...
  • From: "Peters, Brandon" <email@hidden>
  • Date: Thu, 28 Aug 2014 01:17:42 +0000
  • Thread-topic: CALayer disappears on view resize...

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 (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 disappears on view resize...
      • From: Kyle Sluder <email@hidden>
  • Prev by Date: Re: What exactly does NSDocumentController do when there's no NSDocument architecture?
  • Next by Date: Re: CALayer disappears on view resize...
  • Previous by thread: Re: Prompting user (NSAlert) during document reading
  • Next by thread: Re: CALayer disappears on view resize...
  • Index(es):
    • Date
    • Thread