Note that there are some explanatory texts on larger screens.

plurals
  1. POdynamic resizing of UICollectionView using intrinsic size within an autolayout
    primarykey
    data
    text
    <p>I am trying to implement a calendar using UICollectionView which has a similar scrolling behaviour to the built in calendar app when changing months. At the moment the view is flickering as the resize occurs between months. </p> <p>I am using a UICollectionViewScrollLayout with a UICollectionView with 10000 indexes in 1 section. The cells are filled by calculating the day for an index. The problem I am having is when trying to resize the view to fit the correct number of weeks for the month, the collectionview doesn't appear to draw in the cells quickly enough as the scrolling and view size change happens. Having slowed the animation down, as the view size changes, it appears that cells are being removed too early from the view. This happens both with a reducing and enlarging the view. Ie, as they are about to scroll off the view they are removed before scrolling out of the view.</p> <p>The layout is all done using autolayout and there is a fixed view above and then a resizable view below. As the size of the collection view changes the view below changes to fill the space. The only way I seem to have managed to achieve this behavior it is by changing the intrinsic size as per the code below. I have tried changing the frame/bounds but it doesn't seem to work with autolayout. Am I going about the resizing of the view in the right way?</p> <p>Should I be moving the behaviour to the viewcontroller and change the constraints pinning the height instead. </p> <pre><code>// Scroll the view to the date given. -(void) moveViewToDate:(NSDate*) date { NSIndexPath *indexPath=[self indexPathForFirstDayInMonth:date]; [self scrollToItemAtIndexPath:indexPath atScrollPosition:UICollectionViewScrollPositionTop animated:YES]; [UIView animateWithDuration:0.25f animations:^{ self.isize=[self weeksInViewForDate:date]; [self invalidateIntrinsicContentSize]; [self.superview layoutIfNeeded]; }]; } -(CGSize)intrinsicContentSize { return CGSizeMake(322,self.isize*46); } </code></pre>
    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.
 

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