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

Rya*_*yan 12 iphone objective-c ios uicollectionview uicollectionviewcell

当你在iPhone的照片应用程序(或几乎所有其他应用程序中)中点击照片时,我想复制完全相同的didSelect animation/segue,其中照片从单元格本身放大到模态视图控制器,并最小化到任何地方被解雇时属于网格.

我试过谷歌搜索但找不到任何关于此的文章.

Bou*_*rne 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
}];
Run Code Online (Sandbox Code Playgroud)

这不是很好的弹出动画,但它应该看起来还不错.