• 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: Seriously confused by behavior of NSAffineTransform
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Seriously confused by behavior of NSAffineTransform


  • Subject: Re: Seriously confused by behavior of NSAffineTransform
  • From: Ken Tozier <email@hidden>
  • Date: Sat, 2 Oct 2010 13:05:44 -0400

On Oct 2, 2010, at 9:22 AM, Matt Neuburg wrote:

> Perhaps it might be useful if you were to show some code? At least show
> where you're using a transform and what transform you're using. What does
> "apply a scaling transform to a page view" mean?
>
> A transform is just a way of affecting subsequent drawing in a graphics
> context (in particular, the current context). It's useful, for example, in
> an NSView's drawRect: implementation to let the coordinate system do the
> calculation for you so you don't have to do it. Drawing a rotated rectangle
> would involve all sorts of nasty trig, so instead you rotate the coordinate
> system and draw a normal rectangle, etc.

I decided to simplify and created a project just for exploring transforms. Long story short, I still find them extremely counter intuitive. After futzing with transforms for a few hours, I decided to try a different tack. TI ended up writing a base class (see below) for all my apps views which does exactly what I want re scaling "page" views. When I call the "setScale" method, it scales both the origin and size of a view and calls [self setFrame] which propagates "setScale" to all the subviews. How would I get the same sort of behavior using transforms?

@interface UIView : NSView
{
	float	currentScale;

	NSRect	fullFrame,
		currentFrame;
}

- (void) setScale:(NSNumber *) inScale;

@end


@implementation UIView

- (id) initWithFrame:(NSRect) inFrame
{
	self = [super initWithFrame: inFrame];
	{
		fullFrame	= inFrame;
		currentFrame	= inFrame;
		currentScale	= 1;

		[self setAutoresizesSubviews: NO];
	}

	return self;
}

- (void) setScale:(NSNumber *) inScale
{
	currentScale		= [inScale floatValue];

	NSRect	newFrame	= NSMakeRect(currentFrame.origin.x * currentScale,
					currentFrame.origin.y * currentScale,
					currentFrame.size.width * currentScale,
					currentFrame.size.height * currentScale);

	[self setFrame: newFrame];
}


- (void) setFrame:(NSRect) inFrame
{
	[super setFrame: inFrame];

	currentFrame		= inFrame;

	[[self subviews] makeObjectsPerformSelector: @selector(setScale:) withObject: [NSNumber numberWithFloat: currentScale]];
}

@end


_______________________________________________

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: Seriously confused by behavior of NSAffineTransform
      • From: Kyle Sluder <email@hidden>
References: 
 >Re: Seriously confused by behavior of NSAffineTransform (From: Matt Neuburg <email@hidden>)

  • Prev by Date: Re: App works in debugger, won't launch in Finder
  • Next by Date: Re: Seriously confused by behavior of NSAffineTransform
  • Previous by thread: Re: Seriously confused by behavior of NSAffineTransform
  • Next by thread: Re: Seriously confused by behavior of NSAffineTransform
  • Index(es):
    • Date
    • Thread