RAPhotoPreviewController.m 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. return previewVC;
  20. }
  21. - (void)viewDidLoad {
  22. [super viewDidLoad];
  23. // Do any additional setup after loading the view.
  24. if (@available(iOS 11.0, *)) {
  25. self.photoScrollView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
  26. } else {
  27. self.automaticallyAdjustsScrollViewInsets = NO;
  28. }
  29. self.photoImageView.image = self.image;
  30. [self configureNavigationBar];
  31. }
  32. - (void)didReceiveMemoryWarning {
  33. [super didReceiveMemoryWarning];
  34. // Dispose of any resources that can be recreated.
  35. }
  36. - (void)configureNavigationBar {
  37. UIBarButtonItem *deleteItem = [[UIBarButtonItem alloc] initWithTitle:@"delete" style:UIBarButtonItemStylePlain target:self action:@selector(deleteActionClick:)];
  38. self.navigationItem.rightBarButtonItem = deleteItem;
  39. }
  40. #pragma mark - Action
  41. - (void)deleteActionClick:(UIBarButtonItem *)sender {
  42. UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:nil message:@"Are you sure you want to delete it" preferredStyle:UIAlertControllerStyleAlert];
  43. __weak typeof(self) weakSelf = self;
  44. UIAlertAction *yesAction = [UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  45. if (weakSelf.completion) {
  46. weakSelf.completion();
  47. }
  48. [weakSelf.navigationController popViewControllerAnimated:YES];
  49. }];
  50. UIAlertAction *noAction = [UIAlertAction actionWithTitle:@"No" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  51. }];
  52. [alertVC addAction:noAction];
  53. [alertVC addAction:yesAction];
  54. [self presentViewController:alertVC animated:YES completion:nil];
  55. }
  56. #pragma mark - Scroll Delegate
  57. - (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView {
  58. return self.photoImageView;
  59. }
  60. @end