-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMBXImageViewController.m
79 lines (61 loc) · 1.82 KB
/
MBXImageViewController.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
//
// PWImageViewController.m
// ParkWhiz
//
// Created by Mo Bitar on 12/11/14.
// Copyright (c) 2014 ParkWhiz. All rights reserved.
//
#import "MBXImageViewController.h"
#import "MBQuickKit.h"
@interface MBXImageViewController () <UIScrollViewDelegate>
@property (weak, nonatomic) IBOutlet UIScrollView *scrollView;
@property (weak, nonatomic) IBOutlet UIImageView *imageView;
@property (nonatomic) UIImage *image;
@end
@implementation MBXImageViewController
- (instancetype)initWithImage:(UIImage *)image
{
if(self = [super init]) {
self.image = image;
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
if(self.zoomEnabled) {
self.scrollView.minimumZoomScale = 1.0;
self.scrollView.maximumZoomScale = 6.0;
}
self.view.backgroundColor = self.view.backgroundColor ?: [UIColor blackColor];
self.imageView.image = self.image;
self.imageView.contentMode = self.imageViewContentMode;
[self configureNavBar];
}
- (void)viewDidLayoutSubviews
{
[super viewDidLayoutSubviews];
[self.imageView trailVerticallyTo:self.navigationController.navigationBar andFitInView:self.view];
[self.imageView centerInSuperview];
self.scrollView.contentSize = self.imageView.size;
}
- (void)configureNavBar
{
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(donePressed)];
}
- (void)donePressed
{
[self dismissViewControllerAnimated:YES completion:nil];
}
#pragma mark - Scroll View
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView
{
if(self.zoomEnabled) {
return self.imageView;
}
return nil;
}
- (void)scrollViewDidEndZooming:(UIScrollView *)scrollView withView:(UIView *)view atScale:(CGFloat)scale
{
}
@end