RAPhotoPreviewController.m 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. //
  2. // RAPhotoPreviewController.m
  3. // Apex And Drivers
  4. //
  5. // Created by Jack on 2018/6/5.
  6. // Copyright © 2018年 USAI. All rights reserved.
  7. //
  8. #import "RAPhotoPreviewController.h"
  9. @interface RAPhotoPreviewController () <UIScrollViewDelegate>
  10. @property (strong, nonatomic) IBOutlet UIImageView *photoImageView;
  11. @property (strong, nonatomic) IBOutlet UIScrollView *photoScrollView;
  12. @end
  13. @implementation RAPhotoPreviewController
  14. + (NSString *)storyboardID {
  15. return NSStringFromClass([self class]);
  16. }
  17. + (instancetype)viewControllerFromStoryboard {
  18. RAPhotoPreviewController *previewVC = [[UIStoryboard storyboardWithName:@"PhotoPreview" bundle:nil] instantiateViewControllerWithIdentifier:[self storyboardID]];
  19. previewVC.canDelete = YES;
  20. return previewVC;
  21. }
  22. - (void)viewDidLoad {
  23. [super viewDidLoad];
  24. // Do any additional setup after loading the view.
  25. if (@available(iOS 11.0, *)) {
  26. self.photoScrollView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
  27. }
  28. // else {
  29. // self.automaticallyAdjustsScrollViewInsets = NO;
  30. // }
  31. self.photoImageView.image = self.image;
  32. [self configureNavigationBar];
  33. }
  34. - (void)didReceiveMemoryWarning {
  35. [super didReceiveMemoryWarning];
  36. // Dispose of any resources that can be recreated.
  37. }
  38. - (void)configureNavigationBar {
  39. if (self.canDelete) {
  40. UIBarButtonItem *deleteItem = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"delete", nil) style:UIBarButtonItemStylePlain target:self action:@selector(deleteActionClick:)];
  41. self.navigationItem.rightBarButtonItem = deleteItem;
  42. }
  43. }
  44. #pragma mark - Action
  45. - (void)deleteActionClick:(UIBarButtonItem *)sender {
  46. UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:nil message:NSLocalizedString(@"Are you sure you want to delete it", nil) preferredStyle:UIAlertControllerStyleAlert];
  47. __weak typeof(self) weakSelf = self;
  48. UIAlertAction *yesAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"YES", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  49. if (weakSelf.completion) {
  50. weakSelf.completion();
  51. }
  52. [weakSelf.navigationController popViewControllerAnimated:YES];
  53. }];
  54. UIAlertAction *noAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"NO", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  55. }];
  56. [alertVC addAction:noAction];
  57. [alertVC addAction:yesAction];
  58. [self presentViewController:alertVC animated:YES completion:nil];
  59. }
  60. #pragma mark - Scroll Delegate
  61. - (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView {
  62. return self.photoImageView;
  63. }
  64. @end