| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- //
- // RAPhotoPreviewController.m
- // Apex And Drivers
- //
- // Created by Jack on 2018/6/5.
- // Copyright © 2018年 USAI. All rights reserved.
- //
- #import "RAPhotoPreviewController.h"
- @interface RAPhotoPreviewController () <UIScrollViewDelegate>
- @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:@"delete" style:UIBarButtonItemStylePlain target:self action:@selector(deleteActionClick:)];
- self.navigationItem.rightBarButtonItem = deleteItem;
- }
- }
- #pragma mark - Action
- - (void)deleteActionClick:(UIBarButtonItem *)sender {
-
- UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:nil message:@"Are you sure you want to delete it" preferredStyle:UIAlertControllerStyleAlert];
- __weak typeof(self) weakSelf = self;
- UIAlertAction *yesAction = [UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
- if (weakSelf.completion) {
- weakSelf.completion();
- }
- [weakSelf.navigationController popViewControllerAnimated:YES];
- }];
- UIAlertAction *noAction = [UIAlertAction actionWithTitle:@"No" 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
|