我想要复制iPhone的照片应用程序中当您点击一张照片时所看到的完全相同的didSelect动画/ segue (或者几乎在其他每个应用程序中),其中照片从单元格本身放大到模态视图控制器,然后在解除时最小化到其所属的网格位置。
我尝试过搜索,但没有找到任何关于此的文章。
我尝试过搜索,但没有找到任何关于此的文章。
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