UIScrollView contentSize有最大值吗?

rkl*_*_de 6 iphone uiscrollview contentsize

我正在开发一个带有Ganttchart的小型iPad应用程序,该应用程序将在过去25小时内显示事件.我有5个缩放级别,分别为1小时30分钟,15分钟,5分钟和1分钟.我的细胞宽度为30像素.从每小时的Zoomlevel开始,我有25*30像素= 750宽度的内容(不需要滚动).当缩放单元格宽度保持不变时,只会有更多单元格,我可以水平滚动.它适用于30,15和5分钟.事情发生在1分钟级别(宽度为45000像素(30*1500))时,事情开始出错.滚动视图冻结(我仍然可以滚动,但显示不会更新).

drawRect:已经完成(所以它应该被正确绘制).我可以在按钮上看到一个小滚动条(甚至到达终点).所以我试图警惕宽度,似乎问题从大约16300像素宽度开始.有没有解决这个问题?还是任何一种解决方案?

我使用带有uiview(Ganttchartview)的ScrollView,其中drawRect:我已经超载了.

放大CELL_WIDTH为30且zoomLevels为25,50,75,300,1500

 -(IBAction) zoomIn:(id)sender {
    self.zoomIndex++;
    int width = CELL_WIDTH * [[self.zoomLevels objectAtIndex: self.zoomIndex] intValue];
    self.frame = CGRectMake(self.frame.origin.x, self.frame.origin.y, width, self.frame.size.height);
    [self.parentView setContentSize: CGSizeMake(self.frame.size.width, self.frame.size.height)];
    [self setNeedsDisplay];
}
Run Code Online (Sandbox Code Playgroud)

drawRect绘制线条的位置

- (void)drawRect:(CGRect)rect {
Run Code Online (Sandbox Code Playgroud)
    CGContextRef context = UIGraphicsGetCurrentContext();
    CGContextSetStrokeColorWithColor(context, [UIColor blackColor].CGColor);
    CGContextSetLineWidth(context, 2.0);        
    int interval = [[self.zoomLevels objectAtIndex: self.zoomIndex] intValue];
    int width = CELL_WIDTH;
    for (int i = 0; i < interval; i++) {
        CGContextMoveToPoint(context, width * (i +1), START_AT); 
        CGContextAddLineToPoint(context, width * (i +1), rect.size.height); 
        CGContextStrokePath(context);
    }
    for (int i = 0; i < NUMBER_OF_ROWS; i++) {
        CGContextMoveToPoint(context, 0, START_AT + i * CELL_WIDTH); 
        CGContextAddLineToPoint(context, rect.size.width, START_AT + i * CELL_WIDTH); 
        CGContextStrokePath(context);
    }
}
Run Code Online (Sandbox Code Playgroud)

vig*_*o24 3

我建议此类应用程序使用无限滚动视图。这包括基于固定(且有限)的 contentSize 的编码技巧,为用户提供无限滚动的体验。WWDC 2011 上已经展示了一个很好的例子,因此如果您有开发者帐户,则可以下载视频(有一个专门用于滚动视图的部分)。或者你可以参考网上的一些例子。当然,您需要重构代码,以便仅加载所需的内容,而不加载可能填充可用内存的全部内容。