类似微博微信的照片浏览器:PhotoBrowser

jopen 9年前

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.open-open.com/lib/view/home/1441280745471