如何防止UIScrollview中的嵌入式UIView被剪裁

时间:2010-03-19 15:30:47

标签: iphone cocoa-touch uiview ipad uiscrollview

我有一个iPad UIView子类(我们将调用LargerUIView),我通过drawRect做了一堆绘图:一旦被问到。这一切似乎都有效,看起来像我喜欢的方式。我现在正试图让滚动工作(只是在横向开始),但是当我尝试滚动时,下面显示的是黑色(即,似乎从未被绘制过)。这并不让我感到惊讶,因为它很可能被剪掉了。寻找建议。以下是我到目前为止所做的事情:

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;
}

有什么建议吗?尝试将“setClipsToBounds”更改为NO。

1 个答案:

答案 0 :(得分:0)

叹息。真傻。在InterfaceBuilder中,LargerUIView设置得更小。忘了添加这样一行:

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

糟糕。