Re: Rotating an image in an NSImageView subclass
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:
-jcr
|
_______________________________________________
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