我正在尝试使用我的集合视图选择创建一个酷炫的动画。基本上,我有一个显示照片单元格的集合视图。我想要发生的是,将单元格从其位置弹出,缩放并移动到屏幕中心,在那里用户将被提示确认选择。
这是我的代码,但目前动画采用单元格的原始框架位置,因此如果我滚动,它不会考虑到框架位置已不再相同。
这是我的代码,但目前动画采用单元格的原始框架位置,因此如果我滚动,它不会考虑到框架位置已不再相同。
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
PhotoCell *cell = (PhotoCell *)[collectionView cellForItemAtIndexPath:indexPath];
collectionView.allowsSelection = NO;
[self createAnimationWithCell:cell];
}
- (void)createAnimationWithCell:(PhotoCell *)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;
}];
}