PhotoBrowser
Support Storyboard using PBImageScrollView.
PhotoBrowser是一款輕量的圖片瀏覽器,類似微信、微博的圖片瀏覽器。
現在,名為 SlidingPhoto 的純 Swift 版本已經可用。
UITableView
API 一樣,我們有DataSource
一個用於載入資料和處理作業Delegate
PhotoBrowser
您想要透過符合協定PBViewControllerDataSource
呈現多少頁並實作numberOfPagesInViewController:
選擇器pb_startPage
屬性設定初始化頁面PBViewControllerDataSource
並實作viewController:imageForPageAtIndex:
選擇器PBViewControllerDataSource
並實作viewController:presentImageView:forPageAtIndex:progressHandler
選擇器PBViewControllerDataSource
協定並實作thumbViewForPageAtIndex:
告訴imageView的開始和結束位置PBViewControllerDelegate
並實作viewController:didSingleTapedPageAtIndex:presentedImage:
或viewController:didLongPressedPageAtIndex:presentedImage:
處理點選或長按操作...
PBViewController *pbViewController = [PBViewController new ];
// Use your own subclass of UIImageView to display.
pbViewController.imageViewClass = PBImageView.class;
pbViewController.pb_dataSource = self;
pbViewController.pb_delegate = self;
pbViewController.pb_startPage = sender.tag;
[ self presentViewController: pbViewController animated: YES completion: nil ];
...
...
# pragma mark - PBViewControllerDataSource
- ( NSInteger )numberOfPagesInViewController:(PBViewController *)viewController {
return self. frames . count ;
}
- ( void )viewController:(PBViewController *)viewController presentImageView:(UIImageView *)imageView forPageAtIndex:( NSInteger )index progressHandler:( void (^)( NSInteger , NSInteger ))progressHandler {
NSString *url = [ NSString stringWithFormat: @" https://raw.githubusercontent.com/cuzv/PhotoBrowser/dev/Example/Assets/ %@ .jpg " , @( index + 1 )];
UIImage *placeholder = self. imageViews [ index ]. image ;
[imageView sd_setImageWithURL: [ NSURL URLWithString: url]
placeholderImage: placeholder
options: 0
progress: progressHandler
completed: ^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
}];
}
- (UIView *)thumbViewForPageAtIndex:( NSInteger )index {
if (self. thumb ) {
return self. imageViews [ index ];
}
return nil ;
}
# pragma mark - PBViewControllerDelegate
- ( void )viewController:(PBViewController *)viewController didSingleTapedPageAtIndex:( NSInteger )index presentedImage:(UIImage *)presentedImage {
[ self dismissViewControllerAnimated: YES completion: nil ];
}
有關更多信息,請查看項目中的示例。
PhotoBrowser
在 MIT 許可下可用。有關詳細信息,請參閱許可證文件。