Note that there are some explanatory texts on larger screens.

plurals
  1. POScrollViewSuite Example Code Uses More Memory than Necessary?
    primarykey
    data
    text
    <p>There is problem in <a href="http://developer.apple.com/library/ios/#samplecode/ScrollViewSuite/Introduction/Intro.html" rel="nofollow">ScrollViewSuite</a>. it use more memory than needed . for example:</p> <ol> <li>Load image in 25% and measure memory (4 MB) </li> <li>Zoom in image to 100% and measure memory (30 MB)</li> <li>Zoom out to 25% and measure memory (30 MB) - why 30 ? it must use only 4 MB - that is the problem.</li> </ol> <p>How to fix the problem ?</p> <pre><code>/***********************************************************************************/ /* Most of the work of tiling is done in layoutSubviews, which we override here. */ /* We recycle the tiles that are no longer in the visible bounds of the scrollView */ /* and we add any tiles that should now be present but are missing. */ /***********************************************************************************/ - (void)layoutSubviews { [self updateResolution]; NSLog(@"layoutSubviews "); [super layoutSubviews]; CGRect visibleBounds = [self bounds]; // first recycle all tiles that are no longer visible for (UIView *tile in [tileContainerView subviews]) { // We want to see if the tiles intersect our (i.e. the scrollView's) bounds, so we need to convert their // frames to our own coordinate system CGRect scaledTileFrame = [tileContainerView convertRect:[tile frame] toView:self]; // If the tile doesn't intersect, it's not visible, so we can recycle it if (! CGRectIntersectsRect(scaledTileFrame, visibleBounds)) { [reusableTiles addObject:tile]; [tile removeFromSuperview]; } } // calculate which rows and columns are visible by doing a bunch of math. float scaledTileWidth = [self tileSize].width * [self zoomScale]; float scaledTileHeight = [self tileSize].height * [self zoomScale]; int maxRow = floorf([tileContainerView frame].size.height / scaledTileHeight); // this is the maximum possible row int maxCol = floorf([tileContainerView frame].size.width / scaledTileWidth); // and the maximum possible column int firstNeededRow = MAX(0, floorf(visibleBounds.origin.y / scaledTileHeight)); int firstNeededCol = MAX(0, floorf(visibleBounds.origin.x / scaledTileWidth)); int lastNeededRow = MIN(maxRow, floorf(CGRectGetMaxY(visibleBounds) / scaledTileHeight)); int lastNeededCol = MIN(maxCol, floorf(CGRectGetMaxX(visibleBounds) / scaledTileWidth)); // iterate through needed rows and columns, adding any tiles that are missing for (int row = firstNeededRow; row &lt;= lastNeededRow; row++) { for (int col = firstNeededCol; col &lt;= lastNeededCol; col++) { BOOL tileIsMissing = (firstVisibleRow &gt; row || firstVisibleColumn &gt; col || lastVisibleRow &lt; row || lastVisibleColumn &lt; col); if (tileIsMissing) { UIView *tile = [dataSource tiledScrollView:self tileForRow:row column:col resolution:resolution]; // set the tile's frame so we insert it at the correct position CGRect frame = CGRectMake([self tileSize].width * col, [self tileSize].height * row, [self tileSize].width, [self tileSize].height); [tile setFrame:frame]; [tileContainerView addSubview:tile]; // annotateTile draws green lines and tile numbers on the tiles for illustration purposes. [self annotateTile:tile]; } } } // update our record of which rows/cols are visible firstVisibleRow = firstNeededRow; firstVisibleColumn = firstNeededCol; lastVisibleRow = lastNeededRow; lastVisibleColumn = lastNeededCol; } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload