简体   繁体   English

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

[英]UICollectionView tapped animation like iPhone photos app

I would like to replicate the exact same didSelect animation / segue when you tap a photo in the iPhone's photo app (or in almost every so other app) where the photo enlarges from the cell itself into a modal view controller, and minimizes to wherever it belongs to in the grid when dismissed. 当你在iPhone的照片应用程序(或几乎所有其他应用程序中)中点击照片时,我想复制完全相同的didSelect animation / segue,其中照片从单元格本身放大到模态视图控制器,并最小化到任何地方被解雇时属于网格。

I tried googling but couldn't find any articles about this. 我试过谷歌搜索但找不到任何关于此的文章。

There are many public repos on git that could probably do what you want. git上有很多公共回购可能会做你想要的。 Some stuff I've found: 我找到的一些东西:
https://github.com/mariohahn/MHVideoPhotoGallery https://github.com/mariohahn/MHVideoPhotoGallery
https://github.com/mwaterfall/MWPhotoBrowser https://github.com/mwaterfall/MWPhotoBrowser

Those may be overly complicated. 那些可能过于复杂。 Another option is creating a UIImageView at the same place as the cell and then animating it to fill the screen. 另一种选择是在与单元格相同的位置创建UIImageView,然后设置动画以填充屏幕。 This code assumes the collectionView has an origin at (0,0), if not then simply add the collectionView's offset when calculating the initial frame. 此代码假定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
}];

It's not the nice popping animation but it should still look ok. 这不是很好的弹出动画,但它应该看起来还不错。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何添加照片应用程序之类的动画 - How to add animation like Photos app UICollectionView动画,例如Google Play新闻应用 - UICollectionView Animation like Google Play News app 动画,如卡片应用程序iPhone - Animation like cards app iphone Swift - 在UICollectionView中点击时如何使单元格收缩效果(如ios 12 Shortcut app和App Store应用程序) - Swift - How to make cell shrinking effect when tapped in UICollectionView (like ios 12 Shortcut app and App Store app) 如何使用Swift在iOS Photos应用程序中选择所有UICollectionView单元格? - How to select ALL UICollectionView cells like in the iOS Photos app using Swift? UICollectionView - 复制Photos.app功能 - UICollectionView - replicate Photos.app functionality 复制iPhone的照片应用 - Replicating iPhone's Photos App 像照片一样使用UICollectionView在模式之间进行切换的最佳方法 - The best way to toggle between modes using UICollectionView like in Photos iOS Swift:如何重新创建照片应用程序UICollectionView布局 - iOS Swift: How to recreate a Photos App UICollectionView Layout 如何旋转类似于照片应用程序的UICollectionView并保持当前视图居中? - How to rotate a UICollectionView similar to the photos app and keep the current view centered?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM