views:

367

answers:

2

Hello. I have an iPad UIView subclass (we'll call LargerUIView) with which I do a bunch of drawing via drawRect: once asked. That all appears to be working, and looks the way I like. I'm at the point now of trying to get scrolling working (just in the horizontal to begin), yet when I try to scroll, what shows below is black (ie, appears to have never been drawn). That doesn't surprise me as it's likely been clipped. Looking for suggestions. Here's what I'm doing so far:

MyAppDelegate.m

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    

    CGRect scrollRect = CGRectMake(0, 0, 768, 1024);
    UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:scrollRect];

    LargerUIView *view = (LargerUIView *)[viewController view];
    [scrollView addSubview:view];

    [scrollView setContentSize:CGSizeMake(768, pageHeight)];
    [scrollView setContentMode:UIViewContentModeRedraw];
    [scrollView setClipsToBounds:YES];

    [window addSubview:scrollView];
    [scrollView release];

    // Without this next line, the "frontmost" (ie, most recently added subview)
    // is the target uiview - which is not equipped to handle scrolling/UIEvents
    [window sendSubviewToBack:view];

    // Show it all.
    [window makeKeyAndVisible];

    return YES;
}

Any suggestions? Have tried changing "setClipsToBounds" to NO as well.

A: 

Sigh. How silly. The LargerUIView was set up to be smaller in InterfaceBuilder. Forgot to add a line like this:

[view setBounds:CGRectMake(0, 0, 768, pageHeight)];

Oops.

scc
A: 

Actually, this turned out to be less silly than I originally thought. While the app did indeed load with the correct positioning on load, as soon as I dragged it, it shot back to the wrong positioning within the UIScrollView's bounds.

Solution: Remove the .xib file, and build up the UIView and UIScrollView objects programmatically via [controller loadView]. No offset needed anymore!

scc