我试图用我的收藏 View 选择创建一个很酷的动画。基本上我有一个显示照片单元的 Collection View 。我想要发生的是让单元格弹出其位置,缩放并移动到屏幕中心,提示用户确认选择。
到目前为止,这是我的代码,但目前动画采用单元格的原始帧位置,所以如果我滚动它并没有考虑到帧位置不再相同。
- (void)collectionViewUICollectionView *)collectionView didSelectItemAtIndexPathNSIndexPath *)indexPath{
PhotoCell *cell = (PhotoCell *)[collectionView cellForItemAtIndexPath:indexPath];
collectionView.allowsSelection = NO;
[self createAnimationWithCell:cell];
}
- (void)createAnimationWithCellPhotoCell *)cell {
UIImageView *selectedImage = [[UIImageView alloc] initWithFrame:cell.bounds];
selectedImage.center = cell.center;
selectedImage.image = cell.imageView.image;
[self.view addSubview:selectedImage];
[UIView animateWithDuration:2.5 animations:^{
selectedImage.center = self.view.center;
} completion:^(BOOL finished) {
[selectedImage removeFromSuperview];
self.collectionView.allowsSelection = YES;
}];
}
我自己解决了:
对于那些遇到同样问题的人,我们必须考虑到 Collection View 滚动(偏移)的程度并使用该信息。我创建了一个名为 collectionViewOffset 的变量,并给它一个初始值 0.0
然后使用:
- (void)scrollViewDidScrollUIScrollView *)scrollView
{
// getting the scroll offset
collectionViewOffset = scrollView.contentOffset.y;
NSLog(@"offset: %f", collectionViewOffset);
}
- (void)collectionViewUICollectionView *)collectionView didSelectItemAtIndexPathNSIndexPath *)indexPath{
PhotoCell *cell = (PhotoCell *)[collectionView cellForItemAtIndexPath:indexPath];
//collectionView.allowsSelection = NO;
//collectionView.scrollEnabled = NO;
[cell.superview bringSubviewToFront:cell];
[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) {
}];
}
关于ios - 弹出 collectionview 单元格并缩放 - uicollectionviewcell 动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36233081/
欢迎光临 OStack程序员社区-中国程序员成长平台 (https://ostack.cn/) | Powered by Discuz! X3.4 |