// // RAPhotoPreviewController.m // Apex And Drivers // // Created by Jack on 2018/6/5. // Copyright © 2018年 USAI. All rights reserved. // #import "RAPhotoPreviewController.h" @interface RAPhotoPreviewController () @property (strong, nonatomic) IBOutlet UIImageView *photoImageView; @property (strong, nonatomic) IBOutlet UIScrollView *photoScrollView; @end @implementation RAPhotoPreviewController + (NSString *)storyboardID { return NSStringFromClass([self class]); } + (instancetype)viewControllerFromStoryboard { RAPhotoPreviewController *previewVC = [[UIStoryboard storyboardWithName:@"PhotoPreview" bundle:nil] instantiateViewControllerWithIdentifier:[self storyboardID]]; previewVC.canDelete = YES; return previewVC; } - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. if (@available(iOS 11.0, *)) { self.photoScrollView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever; } // else { // self.automaticallyAdjustsScrollViewInsets = NO; // } self.photoImageView.image = self.image; [self configureNavigationBar]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } - (void)configureNavigationBar { if (self.canDelete) { UIBarButtonItem *deleteItem = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"delete", nil) style:UIBarButtonItemStylePlain target:self action:@selector(deleteActionClick:)]; self.navigationItem.rightBarButtonItem = deleteItem; } } #pragma mark - Action - (void)deleteActionClick:(UIBarButtonItem *)sender { UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:nil message:NSLocalizedString(@"Are you sure you want to delete it", nil) preferredStyle:UIAlertControllerStyleAlert]; __weak typeof(self) weakSelf = self; UIAlertAction *yesAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"YES", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) { if (weakSelf.completion) { weakSelf.completion(); } [weakSelf.navigationController popViewControllerAnimated:YES]; }]; UIAlertAction *noAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"NO", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) { }]; [alertVC addAction:noAction]; [alertVC addAction:yesAction]; [self presentViewController:alertVC animated:YES completion:nil]; } #pragma mark - Scroll Delegate - (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView { return self.photoImageView; } @end