View Single Post
I have spent days trying to figure this out, and have now created a very simple test project which exhibits the problem.


1. when my view initially loads, it just has the checkered background showing, and does not tile the view until I zoom.

2. when scaled to less than 100%, some of my tiles are being drawn black, and some are being only partially drawn, and the rest is black.

Here is a description of my test project:

A) Single view iPad app.

B) In the storyboard, I have added a scrollview and set its minimum scale to 0.2 and maximum to 5. Its class is set to OUIScalingScrollView. Its delegate is the controller, and the controller is linked to it as its scrollView.

C) In the main storyboard, the view controller is set to be my subclass of OUIScalingViewController. I have added one property, which will point to my view. The following is the code for the view controller:

- (void)viewDidLoad
[super viewDidLoad];
self.myView = [[MyView alloc] initWithFrame:CGRectMake(0, 0, 8000, 8000)];
[self.scrollView addSubview:self.myView];

- (OUIScalingView *)viewForZoomingInScrollView:(id)sender {
return self.myView;

- (CGSize)canvasSize {
return self.myView.frame.size;

D) The implementation of my view just draws random colored tiles using the following code:

#define ARC4RANDOM_MAX 0x100000000

- (void)drawScaledContent:(CGRect)rect {
CGContextRef currentContext = UIGraphicsGetCurrentContext();

double r = ((double)arc4random() / ARC4RANDOM_MAX);
double g = ((double)arc4random() / ARC4RANDOM_MAX);
double b = ((double)arc4random() / ARC4RANDOM_MAX);

CGContextSetRGBFillColor(currentContext, r, g, b, 1.0f);
CGContextFillRect(currentContext, self.bounds);


I have checked in OmniGraffle, and those problems are not there, so there is clearly something fundamental I am missing here.

Other things I have tried include:
- turning on and off autolayout.
- trying sizeInitialViewSizeFromCanvasSize in the controller (called from viewDidLoad)
- trying tileVisibleRect in my view (also from viewDidLoad)
- calling setNeedsDisplay on my view and the scroll view.

I also tried just filling the rect passed in to the drawScaledRect: method, but that made the drawing problem worse.

Please help! I have tried everything I can think of to sort this out, and have stripped it back to an absolutely minimal project in order to try to debug it, all to no avail.

(sorry if this is a repost - I posted it last week, but it never seemed to turn up on the forum)