The Omni Group

Go Back   The Omni Group Forums > Developer > Omni Frameworks
FAQ Members List Calendar Search Today's Posts Mark Forums Read

How to work with OUIScalingScrollView Thread Tools Search this Thread Display Modes
I'm trying to use the scaling scroll view, but am not sure how to set it up to do the right thing. I am setting everything up programmatically in a subclass of OUIScalingViewController. The following is the code I have written:

- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
self.scrollView = [OUIScalingScrollView new];
self.scrollView.delegate = self;
self.scrollView.backgroundColor = [UIColor greenColor];
self.scrollView.translatesAutoresizingMaskIntoCons traints = NO;
self.scrollView.minimumZoomScale = 0.25f;
self.scrollView.maximumZoomScale = 5.0f;
[self.view addSubview:self.scrollView];
[self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[sv]|" options:0 metrics:nil views:@{@"sv":self.scrollView}]];
[self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[sv]|" options:0 metrics:nil views:@{@"sv":self.scrollView}]];

self.mapView = [OUIScalingView new];
self.mapView.backgroundColor = [UIColor redColor];
self.mapView.translatesAutoresizingMaskIntoConstra ints = NO;
[self.scrollView addSubview:self.mapView];
self.mapView.frame = CGRectMake(0.0f, 0.0f, 2000.0f, 4000.0f);
self.scrollView.contentSize = self.mapView.frame.size;

UILabel *label = [UILabel new];
label.translatesAutoresizingMaskIntoConstraints = YES;
label.text = @"This is a label.";
label.backgroundColor = [UIColor yellowColor];
[self.mapView addSubview:label];
label.frame = CGRectMake(50, 50, 100, 100);

label = [UILabel new];
label.translatesAutoresizingMaskIntoConstraints = YES;
label.text = @"This is a label.";
label.backgroundColor = [UIColor blueColor];
[self.mapView addSubview:label];
label.frame = CGRectMake(750, 750, 100, 100);

What happens is that when I pinch to zoom out, the whole thing gets zoomed out and says it's going to zoom to fit, and appears to do so at 26% size, but the labels don't scale with the view - well they do while you're pinching, but when you let go, they end up their original size. So the first question is how do I get the view and all its subviews to scale?

When I zoom in, the zoom factor goes up but when I let go, it snaps back to 72%. Why is that, and how do I fix it?

What I want to end up with is something a bit like OmniGraffle where the users can pinch to zoom the canvas, and it does what you expect. My program will resize the canvas as required, adding subviews to represent the different objects I want to draw. I will be able to calculate the canvas size and exact frames of all the graphic objects I want to display.
FYI, I took this same code and applied it to a standard UIScrollView, and it worked just fine (except that it didn't redraw my views on resize, but I seem to have fixed that by setting the content scale factor and setting it to need display).
After the zooming operation is finished, the final scale factor applied by UIScrollView (via blurry/ugly pixel scaling) is accumulated into the inner OUIScalingView.scale property. The UIScrollView's scale is then set back to 100% so that no pixel blurring is done.

The accumulated scale gets used when drawing just that scaling view, via a transform set up either in its draw rect, or if you are using OUITiledScalingView, in the OUIScalingViewTile.

OmniGraffle uses OUITiledScalingView as the superclass of its main canvas view, in fact.

So, this all explains why the UILabels don't get scaled. By design the UIScrollView scale is set back to 100% to avoid blurring and the UILabel's don't get drawn under the influence of the scale factor in the OUIScalingView since their parent view can't force them to draw at a scale factor either (any attempt to do so would scale up the bitmap for their layer w/o making the layer bitmap bigger).
CTO, The Omni Group
Cool, thanks Tim - lucky that I just happened to choose a UILabel to test with, so I now understand how it works... Will do some more experimentation.

BTW, thanks for OmniGraffle - it's a great inspiration showing what you can do on iPad.

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2019, vBulletin Solutions, Inc.