Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I have a workaround that seems to be working for me and should not run amok of Apple's rules for iOS applications.</p> <p>The key is the observation that the large cells bounds are the issue. I've worked around that by ensuring that one edge of the cell is within the viewable area of the scrollable content region. You'll obviously need to subclass the UICollectionViewFlowLayout class or UICollectionViewLayout depending on your needs and make use of the contentOffset value to track where you are in the UIScrollView. </p> <p>I also had to ensure: </p> <pre><code>- (BOOL)shouldInvalidateLayoutForBoundsChange:(CGRect)newBounds </code></pre> <p>returns YES or face a runtime exception indicating the layout was invalid. I keep the edge of the larger cell bound to the left edge in my case. This way you can avoid the erroneous bounds intersection detection for these larger cells. </p> <p>This does create more work depending on how you would like the contents of the cell to be rendered as the width/height of the cell is being updated as you scroll. In my case, the subviews within the cell are relatively simple and do not require a lot of fiddling with.</p> <p>As requested here is an example of my <code>layoutAttributesInRect</code></p> <pre><code>- (NSArray *)layoutAttributesForElementsInRect:(CGRect)rect { NSMutableArray* attributes = [NSMutableArray array]; NSArray *vertical = myVerticalCellsStore.cells; NSInteger startRow = floor(rect.origin.y * (vertical.count)/ (vertical.count * verticalViewHeight + verticalViewSpacing * 2)); startRow = (startRow &lt; 0) ? 0 : startRow; for (NSInteger i = startRow; i &lt; vertical.count &amp;&amp; (rect.origin.y + rect.size.height &gt;= i * verticalViewHeight); i++) { NSArray *horizontals = myHorizontalStore.horizontalCells; UICollectionViewLayoutAttributes *verticalAttr = [self layoutAttributesForSupplementaryViewOfKind:@"vertical" atIndexPath:[NSIndexPath indexPathForItem:0 inSection:i]]; if (CGRectIntersectsRect(verticalAttr.frame, rect)) { [attributes addObject:verticalAttr]; } BOOL foundAnElement = NO; for (NSInteger j = 0 ; j &lt; horizontals.count; j++) { MYViewLayoutAttributes *attr = (MyViewLayoutAttributes *)[self layoutAttributesForItemAtIndexPath:[NSIndexPath indexPathForItem:j inSection:i]]; if (CGRectIntersectsRect(rect, attr.frame)) { [attributes addObject: attr]; foundAnElement = YES; } else if (foundAnElement) { break; } } } return attributes; } </code></pre> <p>This is my sanitized code. Basically I calculate about were the first cell should be based on the cell height. In my case that is fixed, so the calculation is pretty easy. But my horizontal elements have various widths. So the inner loop is really about figuring out the right number of horizontal cells to include in the attributes array. There I'm using the <code>CGRectIntersectsRect</code> to determine if the cell intersects. Then the loop keeps going until the intersection fails. And if at least one horizontal cell has been found the loop will break. Hope that helps.</p>
    singulars
    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.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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