Question

I made up a NSScrollView within IB and checked the allow magnification box. What does this actually do?

This is what I found in Apples examples where a manual magnification is implemented:

- (void)magnifyWithEvent:(NSEvent *)event {

    [resultsField setStringValue:

    [NSString stringWithFormat:@"Magnification value is %f", [event magnification]]];

    NSSize newSize;

    newSize.height = self.frame.size.height * ([event magnification] + 1.0);

    newSize.width = self.frame.size.width * ([event magnification] + 1.0);

    [self setFrameSize:newSize];

}

Using allow magnification also resizes everything within the view so it can't be, like above, setting the frame size.
So is it something like using scaleUnitSquareToSize: to manipulate the coordinate system?

No correct solution

OTHER TIPS

I haven't used this, but the old way of scaling view contents was to change the bounds of a view while keeping its frame at the same size. That effectively transformed the coordinate system to draw everything bigger (and most things outside the view).

My guess would be that automatic magnification listens to pinch/unpinch events on the trackpad and scales the bounds up/down in response.

Looking at the docs, it looks like this checkbox sets the -allowsMagnification property. magnification seems to have the same effect as changing the bounds, but is independent. There is a magnification property and minMagnification and maxMagnification properties. So pinching will adjust the magnification property, which in turn causes larger drawing.

My guess would be that magnification is just taken into account when setting up the context transformation matrix inside lockFocus. I hope they also updated scaleUnitSquare and the others appropriately, but those aren't really needed for your drawings to end up the right size, I think.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top