最近空下来整理一下以前写的一些小控件,这是一个图片浏览的控件,使用Objective-c编写。项目是swift的朋友需要自己bridge一下。
一、功能介绍
- 当用户点击图片进入图片浏览模式,控件会自动计算图片将顶宽显示还是顶长显示。
- 进入图片浏览模式之后,双指和双击都有放大/缩小图片的功能。
-
单击图片退出图片浏览模式。
下图是简单的运行效果:
QQ20180814-102454.gif
二、使用方法
- 将 PhotoBrowseController.h, PhotoBrowseController.m,
PhotoBrowseController.xib 拖入项目中; - 在触发图片浏览模式的地方加入如下代码:
PhotoBrowseViewController* controller =
[[PhotoBrowseViewController alloc] initWithImage:image
lastPageFrame:self.imageView.frame];
- image代表传入的图片;
- lastPageFrame是图片在当前UIViewController显示的UIView中对应的frame; 如果image嵌套在子View中,需要用如下代码转换一下frame:
CGRect frame =
[self.imageView convertRect:self.imageView.bounds toView:self.view];
- 设置controller的present模式,推荐使用如下代码:
controller.modalPresentationStyle = UIModalPresentationOverFullScreen;
controller.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self presentViewController:controller animated:true completion:nil];
三、下载地址
https://github.com/Fanfan2528/PhotoBrowseDemo
喜欢的朋友给的star噢~
网友评论