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 (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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to