Is there a maximum for UIScrollView contentSize?

I am developing a small iPad application with Ganttchart that will show Events in the last 25 hours. I have 5 zoom levels each for 1 hour, 30 minutes, 15 minutes, 5 minutes and 1 min. My cells are 30 pixels wide. Starting with the hourly Zoomlevel, I have a width of 25 * 30 pixels = 750 for the content (no need to scroll yet). When the cell width scaling remains unchanged, there will only be more cells, and I can scroll horizontally. It is great for 30, 15 and 5 minutes. When it comes to the 1-minute level (width 45,000 pixels (30 * 1500), everything starts to go wrong. The scrollview freezes (I can still scroll, but the display does not refresh).

Space drawRect: (so it should be drawn correctly). I see a small scroll bar on the button (it even comes to the end). So I tried to guard the width, and it seems that the problems start with a width of about 16300 pixels. Is there any work for this? Or any solution?

I am using ScrollView with uiview (Ganttchartview) enabled, which drawRect: I am overloaded.

zoom in where CELL_WIDTH is 30 and ZoomLevels are 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]; } 

drawRect where the lines are drawn

 - (void)drawRect:(CGRect)rect { 
  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); } } 
+6
source share
2 answers

I would recommend using an infinite scroll view for such applications. This is a code trick that is based on fixed (and limited) contentSize giving the user the experience of infinite scrolling. A good example was demonstrated at WWDC 2011, so if you have a developer account, you can upload a video (there was a section specifically designed to view scrolling). Or you can refer to some examples on the Internet. Of course, you will need to reorganize your code so that only the necessary content is loaded, and not all the content that could fill the available memory.

+3
source

As far as I know, there is no maximum for contentSize , it fills up until you run out of memory.

Think of it as a bucket where you can fill the water, but only until it overflows. So in this case ...

Therefore, it is recommended to use a UITableView as it has the best built-in memory management.

+1
source

Source: https://habr.com/ru/post/897821/


All Articles