ios - 弹出 collectionview 单元格并缩放 - uicollectionviewcell 动画
<p><p>我试图用我的收藏 View 选择创建一个很酷的动画。基本上我有一个显示照片单元的 Collection View 。我想要发生的是让单元格弹出其位置,缩放并移动到屏幕中心,提示用户确认选择。</p>
<p>到目前为止,这是我的代码,但目前动画采用单元格的原始帧位置,所以如果我滚动它并没有考虑到帧位置不再相同。</p>
<pre><code>- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
PhotoCell *cell = (PhotoCell *);
collectionView.allowsSelection = NO;
;
}
- (void)createAnimationWithCell:(PhotoCell *)cell {
UIImageView *selectedImage = [ initWithFrame:cell.bounds];
selectedImage.center = cell.center;
selectedImage.image = cell.imageView.image;
;
[UIView animateWithDuration:2.5 animations:^{
selectedImage.center = self.view.center;
} completion:^(BOOL finished) {
;
self.collectionView.allowsSelection = YES;
}];
}
</code></pre></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>我自己解决了:</p>
<p>对于那些遇到同样问题的人,我们必须考虑到 Collection View 滚动(偏移)的程度并使用该信息。我创建了一个名为 collectionViewOffset 的变量,并给它一个初始值 0.0</p>
<p>然后使用:</p>
<pre><code>- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
// getting the scroll offset
collectionViewOffset = scrollView.contentOffset.y;
NSLog(@"offset: %f", collectionViewOffset);
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
PhotoCell *cell = (PhotoCell *);
//collectionView.allowsSelection = NO;
//collectionView.scrollEnabled = NO;
;
[UIView animateWithDuration:2.0 delay:0 usingSpringWithDamping:0.7 initialSpringVelocity:.2 options:UIViewAnimationOptionCurveLinear animations:^{
cell.center = CGPointMake(self.view.vWidth/2, self.bannerView.vBottomEdge + collectionViewOffset + 40);
} completion:^(BOOL finished) {
}];
}
</code></pre></p>
<p style="font-size: 20px;">关于ios - 弹出 collectionview 单元格并缩放 - uicollectionviewcell 动画,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/36233081/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/36233081/
</a>
</p>
页:
[1]