优雅的图片画廊。它可以从小图缩放显示,并且可以通过酷炫的动画进行拖动手势来关闭。
我从中派生并定制的加载指示器组件在这里
《KYPhotoGallery.h》:
/*
*
@parm: tappedImageView 当前点击的图片视图
@parm: imagesUrls 所有图片的URL链接
@parm: currentIndex 当前图片的序号,第一张图请传入1,第二张为2,以此类推...
*
*/
-(id)initWithTappedImageView:(UIImageView *)tappedImageView andImageUrls:(NSMutableArray *)imagesUrls andInitialIndex:(NSInteger )currentIndex;
/*
*
@property 所有需要显示的UIImageView
*
*/
@property(nonatomic,strong)NSMutableArray *imageViewArray;
-(void)dismissPhotoGalleryAnimated:(BOOL)animated;
-(void)finishAsynDownload:(void(^)(void))finishAsynDownloadBlock;
_photoGallery = [[KYPhotoGallery alloc]initWithTappedImageView:(UIImageView *)sender.view andImageUrls:self.bigImagesUrls andInitialIndex:sender.view.tag];
_photoGallery.imageViewArray = self.imageViewArray;
[_photoGallery finishAsynDownload:^{
[self presentViewController:_photoGallery animated:NO completion:nil];
}];
我使用两个二次函数生成两个因子:factorOfAngle 和 factorOfScale。
factorOfAngle 是使视图在 X 轴周围旋转的因子,而 factorOfScale 当然是使视图缩放的因子。以下是 factorOfAngle 和 factorOfScale 的图表。
然后,将其放入 currentPhoto.layer.transform
中。
CGFloat Y =MIN(SCROLLDISTANCE,MAX(0,ABS(transition.y)));
factorOfAngle = MAX(0,-4/(SCROLLDISTANCE*SCROLLDISTANCE)*Y*(Y-SCROLLDISTANCE));
factorOfScale = MAX(0,-1/(SCROLLDISTANCE*SCROLLDISTANCE)*Y*(Y-2*SCROLLDISTANCE));
CATransform3D t = CATransform3DIdentity;
t.m34 = 1.0/-1000;
t = CATransform3DRotate(t,factorOfAngle*(M_PI/5), transition.y>0?-1:1, 0, 0);
t = CATransform3DScale(t, 1-factorOfScale*0.2, 1-factorOfScale*0.2, 0);
currentPhoto.layer.transform = t;