像iPhone照片应用程序一样实现UICollectionView的点击动画

13
我想要复制iPhone的照片应用程序中当您点击一张照片时所看到的完全相同的didSelect动画/ segue (或者几乎在其他每个应用程序中),其中照片从单元格本身放大到模态视图控制器,然后在解除时最小化到其所属的网格位置。

我尝试过搜索,但没有找到任何关于此的文章。


这可能会对你有所帮助:https://github.com/mariohahn/MHVideoPhotoGallery。它有许多功能示例。为使其正常工作,您需要使用过渡和动画类。 - Dima
这个可能会回答你的问题。 - James Graham
1个回答

7
有许多公共存储库在git上,可能可以满足您的需求。一些我找到的东西:
https://github.com/mariohahn/MHVideoPhotoGallery
https://github.com/mwaterfall/MWPhotoBrowser

这些可能过于复杂。另一个选择是在与单元格相同的位置创建UIImageView,然后将其动画化以填充屏幕。此代码假定collectionView在(0,0)处具有起点,如果不是,则在计算初始框架时简单地添加collectionView的偏移量。
collectionView.scrollEnabled = false; // disable scrolling so view won't move
CGPoint innerOffset = collectionView.contentOffset; // offset of content view due to scrolling
UICollectionViewLayoutAttributes *attributes = [collectionView layoutAttributesForItemAtIndexPath:[NSIndexPath indexPathForItem:index inSection:0] ];
CGRect cellRect = attributes.frame; // frame of cell in contentView

UIImageView *v = [[UIImageView alloc] initWithFrame:CGRectMake(cellRect.origin.x - innerOffset.x, cellRect.origin.y - innerOffset.y, cellRect.size.width, cellRect.size.height)];
[self.view addSubview:v]; // or add to whatever view you want
v.image = image; // set your image
v.contentMode = UIViewContentModeScaleAspectFit; // don't get stupid scaling
// animate
[UIView animateWithDuration:0.5 animations:^{
    [v setFrame:[[UIScreen mainScreen] bounds]]; // assume filling the whole screen
}];

虽然不是很漂亮的弹出动画,但应该看起来还可以。


你是指 cellRect.origin.x - innerOffset.x 而非 cellRect.origin.x + innerOffset.x 吗?(y 同理)。 - Pavlo Razumovskyi

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接