ios - UICollectionView 使用自定义动画更改布局
<p><p>我有两个 collectionViewLayout,verticalFlowLayout 和 fullScreenHorizontalFlowLayout。</p>
<pre><code>@implementation VerticalFlowLayout
- (instancetype)init
{
if (self = ) {
self.sectionInset = UIEdgeInsetsMake(12, 0, 0, 0);
self.minimumLineSpacing = 10;
self.minimumInteritemSpacing = 0;
self.itemSize = CGSizeMake(CGRectGetWidth(.bounds), 244);
}
return self;
}
@end
</code></pre>
<hr/>
<pre><code>@implementation FullScreenFlowLayout
- (instancetype)init
{
if (self = ) {
self.sectionInset = UIEdgeInsetsMake(0, 0, 0, 0);
self.minimumLineSpacing = 10;
self.minimumInteritemSpacing = 0;
self.itemSize = CGSizeMake(CGRectGetWidth(.bounds), CGRectGetHeight(.bounds));
self.scrollDirection = UICollectionViewScrollDirectionHorizontal;
}
return self;
}
</code></pre>
<p>当我选择一个单元格时,我想使用<strong>自定义动画</strong> 更改 collectionView 布局。默认动画是一个线性动画,持续时间为 0.33。</p>
<pre><code> - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
if (]) {
VerticalFlowLayout *flowLayout = ;
[_collectionView setCollectionViewLayout:flowLayout animated:YES completion:^(BOOL finished) {
}];
}
else
animated:YES];
}
</code></pre>
<p>我该怎么做? </p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>只需将 <code>_collectionView.collectionViewFlowLayout = flowLayout</code> 包裹在 <code>UIView</code> 动画 block 中即可。</p>
<pre><code>[UIView animateWithDuration:5.0 delay:0.0 options:UIViewAnimationOptionCurveEaseIn animations:^{
self.collectionView.collectionViewLayout = flowLayout;
} completion:^(BOOL finished) {
if (finished) {
// Do Something
}
}];
</code></pre></p>
<p style="font-size: 20px;">关于ios - UICollectionView 使用自定义动画更改布局,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/33454151/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/33454151/
</a>
</p>
页:
[1]