RAPhotoPreviewController.m 2.6 KB

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