ios - UICollectionView 类似 iPhone 照片应用的点击动画

标签 ios iphone objective-c uicollectionview uicollectionviewcell

当您在 iPhone 的照片应用(或几乎所有其他应用)中点击照片时,我想复制完全相同的 didSelect 动画/segue,照片从单元格本身放大到模态视图 Controller ,并在关闭时最小化到它在网格中所属的任何位置。

我尝试使用谷歌搜索,但找不到任何关于此的文章。

最佳答案

git 上有许多公共(public)存储库可能可以满足您的需求。我发现的一些东西:
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
}];

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

关于ios - UICollectionView 类似 iPhone 照片应用的点击动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22799618/

相关文章:

ios - 拆分属性字符串并保留格式

ios - APNs 远程通知委托(delegate)方法未被调用

iOS UIWebView loadHTMLString 不起作用

android - Jw 播放器无法在移动网络浏览器(Android 和 IOS 设备)中运行

ios - didSelect 执行不等待 didDeSelect 动画结束

ios - 两个 View 层次结构之间的公共(public) subview

iphone - 缩短 UIScrollView 中的触摸延迟?

objective-c - 我如何获得 MKAnnotationView 的坐标?

iOS/Objective-C - 如何在不丢失初始 session 的情况下发送多个 NSURLSessionDataTask 请求?

ios - 自定义 AppDelegate,添加 ViewController 属性,然后设置该属性 : unrecognized selector sent to instance 0x16574320