iOS仿微博图片浏览器

2025-05-29 0 50

knphotobrower
高仿微博图片浏览器

iOS仿微博图片浏览器

photobrower.gif

一.功能描述及要点
1.加载网络九宫格图片,collectionview,scrollview
2.sdwebimage下载图片,knprogresshud显示加载进度
3.高仿微博,显示动画,kntoast提示

二.方法调用

1.创建knphotobrower,并传入相应的参数

?

1

2

3

4

5

6

7

8

9

10
// 每一个图片控件对象, 对一一对应 knphotoitems ,再将多个knphotoitems 对象放入数组

knphotoitems *items = [[knphotoitems alloc] init];

items.url = [urlarr[i] stringbyreplacingoccurrencesofstring:@"thumbnail" withstring:@"bmiddle"];

items.sourceview = imageview;

knphotobrower *photobrower = [[knphotobrower alloc] init];

photobrower.itemsarr = [_itemsarray copy];// knphotoitems对象的数组

photobrower.currentindex = tap.view.tag;// 当前点击的哪个图片

photobrower.actionsheetarr = [self.actionsheetarray mutablecopy];//设置 actionsheet的选项

[photobrower present];// 显示

2.提供代理方法 –> knphotobrowerdelegate

?

1

2

3

4

5

6
/* photobrower 即将消失 */

- (void)photobrowerwilldismiss;

/* photobrower 右上角按钮的点击 */

- (void)photobrowerrightoperationactionwithindex:(nsinteger)index;

/* photobrower 保存图片是否成功 */

- (void)photobrowerwritetosavedphotosalbumstatus:(bool)success;

3.提供 消失方法
[_photobrower dismiss];
4.设置 参数

?

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16
/**

* 是否需要右上角的按钮. default is yes;

*/

@property (nonatomic, assign) bool isneedrighttopbtn;

/**

* 是否需要 顶部 1 / 9 控件 ,default is yes

*/

@property (nonatomic, assign) bool isneedpagenumview;

/**

* 是否需要 底部 uipagecontrol, default is no

*/

@property (nonatomic, assign) bool isneedpagecontrol;

/**

* 存放 actionsheet 弹出框的内容 :nsstring类型

*/

@property (nonatomic, strong) nsmutablearray *actionsheetarr;

5.关于弹出框的内容,可在knphotobrower.m 的operationbtnibaction 方法中增减

?

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46
#pragma mark - 右上角 按钮的点击

- (void)operationbtnibaction{

__weak typeof(self) weakself = self;

if(_actionsheetarr.count != 0){ // 如果是自定义的 选项

knactionsheet *actionsheet = [[knactionsheet alloc] initwithcancelbtntitle:nil destructivebuttontitle:nil otherbtntitlesarr:[_actionsheetarr copy] actionblock:^(nsinteger buttonindex) {

// 让代理知道 是哪个按钮被点击了

if([weakself.delegate respondstoselector:@selector(photobrowerrightoperationactionwithindex:)]){

[weakself.delegate photobrowerrightoperationactionwithindex:buttonindex];

}

#warning 如果传入的 actionsheetarr 有下载图片这一选项. 则在这里调用和下面一样的方法 switch.....,如果没有下载图片,则通过代理方法去实现... 目前不支持删除功能

}];

[actionsheet show];

}else{

knactionsheet *actionsheet = [[knactionsheet alloc] initwithcancelbtntitle:nil destructivebuttontitle:nil otherbtntitlesarr:@[@"保存图片",@"转发微博",@"赞"] actionblock:^(nsinteger buttonindex) {

// 让代理知道 是哪个按钮被点击了

if([weakself.delegate respondstoselector:@selector(photobrowerrightoperationactionwithindex:)]){

[weakself.delegate photobrowerrightoperationactionwithindex:buttonindex];

}

switch (buttonindex) {

case 0:{

sdwebimagemanager *mgr = [sdwebimagemanager sharedmanager];

knphotoitems *items = _itemsarr[_currentindex];

if(![mgr diskimageexistsforurl:[nsurl urlwithstring:items.url]]){

[[kntoast sharetoast] initwithtext:@"图片需要下载完成"];

return ;

}else{

uiimage *image = [[mgr imagecache] imagefromdiskcacheforkey:items.url];

dispatch_async(dispatch_get_main_queue(), ^{

uiimagewritetosavedphotosalbum(image, self, @selector(image:didfinishsavingwitherror:contextinfo:), null);

});

}

}

default:

break;

}

}];

[actionsheet show];

}

}

补充
1.目前适合 九宫格样式,collectionview,scrollview
2.如果有bug, 请在github上通过 '邮箱' 或者 直接issue ,我会尽快修改
github地址: https://github.com/lukane/knphotobrower

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持快网idc。

收藏 (0) 打赏

感谢您的支持,我会继续努力的!

打开微信/支付宝扫一扫,即可进行扫码打赏哦,分享从这里开始,精彩与您同在
点赞 (0)

声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。

快网idc优惠网 建站教程 iOS仿微博图片浏览器 https://www.kuaiidc.com/91762.html

相关文章

发表评论
暂无评论