I'm developing a small iPad-app with a Ganttchart which will show Events in the last 25 hours. I have 5 zoom levels each for 1 hour, 30 min, 15 min, 5 min and 1 min. My cells are 30 pix in width. Starting with the hourly Zoomlevel i have 25 * 30 pixels = 750 width for the content (no need to scroll yet). When zooming the cell width keeps the same, there will just be more cells and I can scroll horizontally. It works perfect for the 30, 15 and 5 mins. When it comes to the 1 minute level (a width of 45000 pixels (30 * 1500), things start to go wrong. The scrollview freezes (I still can kind of scroll, but the display isn't updated).
The drawRect: has been run through (so it should have been drawn correctly). I can see a small scrollbar at the button (it even reaches the end). So I tried to wary the width and it seems that the problems starting at about 16300 pix width. Is there a work around for this? Or any kind of solution?
I use a ScrollView with an included uiview (Ganttchartview) which drawRect: I have overloaded.
zoom in where CELL_WIDTH is 30 and the 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);
}
}
I would recommend for such kind of apps the usage of an infinite scroll view. This consists in a coding trick that based on a fixed (and limited) contentSize gives the user the experience of an infinite scrolling. A good example has been demonstrated at WWDC 2011 so if you have a developer account you can download the videos (there was a section specifically dedicated to scroll views). Or you can refer to some examples in the web. Of course you will need to refactor your code in such way that only needed content is loaded and not the whole content which could fill the available memory.
As far as I know there is no maximum for contentSize
it's fill till you run out of memory.
Consider it as a bucket where you can fill water but only till if overflows. So is the case here...
So it's advisable to use UITableView
as it has better in-built memory management.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With