iOS仿微博圖片瀏覽器_IOS

來源:互聯網
上載者:User

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

以上就是本文的全部內容,希望對大家的學習有所協助,也希望大家多多支援雲棲社區。

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.