類似微博微信的照片瀏覽器:PhotoBrowser

jopen 9年前發布 | 9K 次閱讀 iOS開發 移動開發 PhotoBrowser

PhotoBrowser是一個輕量級的照片瀏覽器,類似于類似微博微信的圖片查看器。
</div>

How to use

  • Like theUITableViewAPI, We haveDataSourceanDelegatefor load data and handle action

  • TellPhotoBrowserhow many pages would you like to present by conforms protocolPBViewControllerDataSourceand implementnumberOfPagesInViewController:selector

  • Optional set the initialize page by invokesetInitializePageIndex:method

  • Use for static Image

    Conforms protocolPBViewControllerDataSourceand implementviewController:imageForPageAtIndex:selector

  • Use for web image

    Conforms protocolPBViewControllerDataSourceand implementviewController:presentImageView:forPageAtIndex:selector

  • Handle action

    Conforms protocolPBViewControllerDataSourceand implementviewController:didSingleTapedPageAtIndex:presentedImage:orviewController:didLongPressedPageAtIndex:presentedImage:handle single tap or long press action

Demo

...
PBViewController *pbViewController = [PBViewController new];
pbViewController.pb_dataSource = self;
pbViewController.pb_delegate = self;
[pbViewController setInitializePageIndex:2];
[self presentViewController:pbViewController animated:YES completion:nil];
...

...
#pragma mark - PBViewControllerDataSource

- (NSInteger)numberOfPagesInViewController:(PBViewController *)viewController {
    return self.urls.count;
}

- (void)viewController:(PBViewController *)viewController presentImageView:(UIImageView *)imageView forPageAtIndex:(NSInteger)index {
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        NSString *path = self.urls[index];
        NSData *data = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:path] options:0 error:nil];
        UIImage *image = [[UIImage alloc] initWithData:data];
        dispatch_async(dispatch_get_main_queue(), ^{
            imageView.image = image;
        });
    });
}
...

...
#pragma mark - PBViewControllerDelegate

- (void)viewController:(PBViewController *)viewController didSingleTapedPageAtIndex:(NSInteger)index presentedImage:(UIImage *)presentedImage {
    NSLog(@"didSingleTapedPageAtIndex: %@", @(index));
    [viewController.presentingViewController dismissViewControllerAnimated:YES completion:nil];
}

- (void)viewController:(PBViewController *)viewController didLongPressedPageAtIndex:(NSInteger)index presentedImage:(UIImage *)presentedImage {
    NSLog(@"didLongPressedPageAtIndex: %@", @(index));
}

項目主頁:http://www.baiduhome.net/lib/view/home/1441280745471

 本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!