【问题标题】:UICollectionView tapped animation like iPhone photos appUICollectionView 像 iPhone 照片应用一样点击动画
【发布时间】:2014-05-13 00:54:20
【问题描述】:

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

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

【问题讨论】:

  • This may help you。它有许多功能示例。为了完成这项工作,您需要使用过渡和动画类。
  • This 可能会回答您的问题

标签: ios iphone objective-c uicollectionview uicollectionviewcell


【解决方案1】:

在 git 上有很多公开的 repos 可能会做你想做的事。我发现的一些东西:
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 相同)。
猜你喜欢
  • 1970-01-01
  • 2013-12-19
  • 2018-03-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多