/
LocalImagesExampleViewController.m
87 lines (68 loc) · 3.4 KB
/
LocalImagesExampleViewController.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
80
81
82
83
84
85
86
87
//
// ViewController.m
// PhotoBrowserSample
//
// Created by Moch Xiao on 8/31/15.
// Copyright (c) 2015 Moch Xiao. All rights reserved.
//
#import "LocalImagesExampleViewController.h"
#import "PBViewController.h"
#import "PBImageScrollerViewController.h"
#import "UIView+PBSnapshot.h"
@interface LocalImagesExampleViewController () <PBViewControllerDataSource, PBViewControllerDelegate>
@property (nonatomic, strong) NSArray *frames;
@property (nonatomic, strong) NSArray *imageViews;
@end
@implementation LocalImagesExampleViewController
- (void)viewDidLoad {
[super viewDidLoad];
for (NSInteger index = 0; index < self.frames.count; ++index) {
UIImageView *imageView = [UIImageView new];
imageView.clipsToBounds = YES;
imageView.contentMode = UIViewContentModeScaleAspectFill;
imageView.backgroundColor = [UIColor blackColor];
imageView.frame = [self.frames[index] CGRectValue];
imageView.tag = index;
imageView.userInteractionEnabled = YES;
NSString *imageName = [NSString stringWithFormat:@"%@", @(index + 1)];
imageView.image = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:imageName ofType:@"jpg"]];
[self.view addSubview:imageView];
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTapedImageView:)];
[imageView addGestureRecognizer:tap];
}
}
- (void)handleTapedImageView:(UITapGestureRecognizer *)sender {
[self _showPhotoBrowser:(UIImageView *)sender.view];
}
- (void)_showPhotoBrowser:(UIImageView *)sender {
PBViewController *pbViewController = [PBViewController new];
pbViewController.pb_dataSource = self;
pbViewController.pb_delegate = self;
pbViewController.pb_startPage = sender.tag;
[self presentViewController:pbViewController animated:YES completion:nil];
}
- (NSArray *)frames {
NSValue *frame1 = [NSValue valueWithCGRect:CGRectMake(20, 80, 80, 80)];
NSValue *frame2 = [NSValue valueWithCGRect:CGRectMake(110, 80, 120, 90)];
NSValue *frame3 = [NSValue valueWithCGRect:CGRectMake(240, 90, 100, 85)];
NSValue *frame4 = [NSValue valueWithCGRect:CGRectMake(20, 180, 75, 110)];
NSValue *frame5 = [NSValue valueWithCGRect:CGRectMake(110, 185, 150, 90)];
NSValue *frame6 = [NSValue valueWithCGRect:CGRectMake(270, 190, 100, 100)];
NSValue *frame7 = [NSValue valueWithCGRect:CGRectMake(20, 300, 90, 90)];
NSValue *frame8 = [NSValue valueWithCGRect:CGRectMake(120, 290, 120, 150)];
NSValue *frame9 = [NSValue valueWithCGRect:CGRectMake(250, 305, 100, 100)];
NSValue *frame10 = [NSValue valueWithCGRect:CGRectMake(120, 470, 120, 100)];
return @[frame1, frame2, frame3, frame4, frame5, frame6, frame7, frame8, frame9, frame10];
}
#pragma mark - PBViewControllerDataSource
- (NSInteger)numberOfPagesInViewController:(PBViewController *)viewController {
return self.frames.count;
}
- (UIImage *)viewController:(PBViewController *)viewController imageForPageAtIndex:(NSInteger)index {
return [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:[@(index + 1) stringValue] ofType:@"jpg"]];
}
#pragma mark - PBViewControllerDelegate
- (void)viewController:(PBViewController *)viewController didLongPressedPageAtIndex:(NSInteger)index presentedImage:(UIImage *)presentedImage {
NSLog(@"didLongPressedPageAtIndex: %@", @(index));
}
@end