gpt4 book ai didi

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

转载 作者:技术小花猫 更新时间:2023-10-29 10:38:08 24 4
gpt4 key购买 nike

当您在 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com