문제

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.

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top