• 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
Re: Rotating an image in an NSImageView subclass
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Rotating an image in an NSImageView subclass


  • Subject: Re: Rotating an image in an NSImageView subclass
  • From: "John C. Randolph" <email@hidden>
  • Date: Mon, 14 Mar 2005 16:17:42 -0800


On Mar 11, 2005, at 9:53 AM, Chris Garaffa wrote:

I’m trying to rotate the image in an NSImageView and running into trouble. So far, I’ve subclassed NSImageView and implemented the following:

@implementation TLRotatingImageView

- (void) drawRect: (NSRect) rect
{
    [super drawRect: rect];
    [[NSGraphicsContext currentContext] saveGraphicsState];
    NSAffineTransform *transform = [NSAffineTransform transform];
    [transform rotateByDegrees: 180.0];
    [transform concat];
    [[NSGraphicsContext currentContext] restoreGraphicsState];
    [self setNeedsDisplay: YES];
}

This method is a no-op.  You're saving the graphics state, modifying it by applying an affine transform, and then restoring the state, which puts back the same transform you started with.  Also, it doesn't make sense to send -setNeedsDisplay: in a -drawRect: method.  You get to the -drawRect: method in the first place because something already marked your view as needing display.

For an example of an NSImageView subclass that can rotate an image (among other things), see:

http://developer.apple.com/samplecode/Transformed_Image/Transformed_Image.html

-jcr

John C. Randolph <email@hidden> (408) 974-8819
Sr. Cocoa Software Engineer,
Apple Worldwide Developer Relations
http://developer.apple.com/cocoa/index.html



 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

References: 
 >Rotating an image in an NSImageView subclass (From: Chris Garaffa <email@hidden>)

  • Prev by Date: Re: Training in Australia?
  • Next by Date: Re: Can't launch carbon XEmacs
  • Previous by thread: Re: Rotating an image in an NSImageView subclass
  • Next by thread: Re: Rotating an image in an NSImageView subclass
  • Index(es):
    • Date
    • Thread