当前位置: 移动技术网 > 移动技术>移动开发>IOS > iOS仿微博图片浏览器

iOS仿微博图片浏览器

2019年07月24日  | 移动技术网移动技术  | 我要评论

knphotobrower
高仿微博图片浏览器


photobrower.gif

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

二.方法调用

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

// 每一个图片控件对象, 对一一对应 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

/* photobrower 即将消失 */
- (void)photobrowerwilldismiss;
/* photobrower 右上角按钮的点击 */
- (void)photobrowerrightoperationactionwithindex:(nsinteger)index;
/* photobrower 保存图片是否成功 */
- (void)photobrowerwritetosavedphotosalbumstatus:(bool)success;

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

/**
 * 是否需要右上角的按钮. 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 方法中增减

#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

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

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网