-
Notifications
You must be signed in to change notification settings - Fork 642
/
Copy pathMenu.m
286 lines (229 loc) · 10.9 KB
/
Menu.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
//
// Menu.m
// IDMPhotoBrowser
//
// Created by Michael Waterfall on 21/10/2010.
// Copyright 2010 d3i. All rights reserved.
//
#import "Menu.h"
@implementation UIAlertView (UIAlertViewWithTitle)
+ (void)showAlertViewWithTitle:(NSString*)title {
[[[UIAlertView alloc] initWithTitle:title message:nil delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil] show];
}
@end
@implementation Menu
#pragma mark - Initialization
- (id)initWithStyle:(UITableViewStyle)style {
if ((self = [super initWithStyle:style])) {
self.title = @"IDMPhotoBrowser";
}
return self;
}
#pragma mark - View Lifecycle
- (void)viewDidLoad
{
[self setupTableViewFooterView];
}
#pragma mark - Layout
- (BOOL)prefersStatusBarHidden
{
return NO;
}
#pragma mark - General
- (void)setupTableViewFooterView
{
UIView *tableViewFooter = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 426 * 0.9 + 40)];
UIButton *buttonWithImageOnScreen1 = [UIButton buttonWithType:UIButtonTypeCustom];
buttonWithImageOnScreen1.frame = CGRectMake(15, 0, 640/3 * 0.9, 426/2 * 0.9);
buttonWithImageOnScreen1.tag = 101;
buttonWithImageOnScreen1.adjustsImageWhenHighlighted = NO;
[buttonWithImageOnScreen1 setImage:[UIImage imageNamed:@"photo1m.jpg"] forState:UIControlStateNormal];
buttonWithImageOnScreen1.imageView.contentMode = UIViewContentModeScaleAspectFill;
buttonWithImageOnScreen1.backgroundColor = [UIColor blackColor];
[buttonWithImageOnScreen1 addTarget:self action:@selector(buttonWithImageOnScreenPressed:) forControlEvents:UIControlEventTouchUpInside];
[tableViewFooter addSubview:buttonWithImageOnScreen1];
UIButton *buttonWithImageOnScreen2 = [UIButton buttonWithType:UIButtonTypeCustom];
buttonWithImageOnScreen2.frame = CGRectMake(15, 426/2 * 0.9 + 20, 640/2 * 0.9, 426/2 * 0.9);
buttonWithImageOnScreen2.tag = 102;
buttonWithImageOnScreen2.adjustsImageWhenHighlighted = NO;
[buttonWithImageOnScreen2 setImage:[UIImage imageNamed:@"photo3m.jpg"] forState:UIControlStateNormal];
buttonWithImageOnScreen2.imageView.contentMode = UIViewContentModeScaleAspectFit;
buttonWithImageOnScreen2.backgroundColor = [UIColor blackColor];
[buttonWithImageOnScreen2 addTarget:self action:@selector(buttonWithImageOnScreenPressed:) forControlEvents:UIControlEventTouchUpInside];
[tableViewFooter addSubview:buttonWithImageOnScreen2];
self.tableView.tableFooterView = tableViewFooter;
}
#pragma mark - Actions
- (void)buttonWithImageOnScreenPressed:(id)sender
{
UIButton *buttonSender = (UIButton*)sender;
// Create an array to store IDMPhoto objects
NSMutableArray *photos = [NSMutableArray new];
IDMPhoto *photo;
if(buttonSender.tag == 101)
{
photo = [IDMPhoto photoWithFilePath:[[NSBundle mainBundle] pathForResource:@"photo1l" ofType:@"jpg"]];
photo.caption = @"Grotto of the Madonna";
[photos addObject:photo];
}
photo = [IDMPhoto photoWithFilePath:[[NSBundle mainBundle] pathForResource:@"photo3l" ofType:@"jpg"]];
photo.caption = @"York Floods";
[photos addObject:photo];
photo = [IDMPhoto photoWithFilePath:[[NSBundle mainBundle] pathForResource:@"photo2l" ofType:@"jpg"]];
photo.caption = @"The London Eye is a giant Ferris wheel situated on the banks of the River Thames, in London, England.";
[photos addObject:photo];
photo = [IDMPhoto photoWithFilePath:[[NSBundle mainBundle] pathForResource:@"photo4l" ofType:@"jpg"]];
photo.caption = @"Campervan";
[photos addObject:photo];
if(buttonSender.tag == 102)
{
photo = [IDMPhoto photoWithFilePath:[[NSBundle mainBundle] pathForResource:@"photo1l" ofType:@"jpg"]];
photo.caption = @"Grotto of the Madonna";
[photos addObject:photo];
}
// Create and setup browser
IDMPhotoBrowser *browser = [[IDMPhotoBrowser alloc] initWithPhotos:photos animatedFromView:sender]; // using initWithPhotos:animatedFromView: method to use the zoom-in animation
browser.delegate = self;
browser.displayActionButton = NO;
browser.displayArrowButton = YES;
browser.displayCounterLabel = YES;
browser.usePopAnimation = YES;
browser.scaleImage = buttonSender.currentImage;
if(buttonSender.tag == 102) browser.useWhiteBackgroundColor = YES;
// Show
[self presentViewController:browser animated:YES completion:nil];
}
#pragma mark - TableView DataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 3;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
NSInteger rows = 0;
if(section == 0)
rows = 1;
else if(section == 1)
rows = 3;
else if(section == 2)
rows = 0;
return rows;
}
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
NSString *title = @"";
if(section == 0)
title = @"Single photo";
else if(section == 1)
title = @"Multiple photos";
else if(section == 2)
title = @"Photos on screen";
return title;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
// Create
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
// Configure
if(indexPath.section == 0)
{
cell.textLabel.text = @"Local photo";
}
else if(indexPath.section == 1)
{
if(indexPath.row == 0)
cell.textLabel.text = @"Local photos";
else if(indexPath.row == 1)
cell.textLabel.text = @"Photos from Flickr";
else if(indexPath.row == 2)
cell.textLabel.text = @"Photos from Flickr - Custom";
}
return cell;
}
#pragma mark - TableView Delegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
// Create an array to store IDMPhoto objects
NSMutableArray *photos = [NSMutableArray new];
IDMPhoto *photo;
if(indexPath.section == 0) // Local photo
{
photo = [IDMPhoto photoWithFilePath:[[NSBundle mainBundle] pathForResource:@"photo2l" ofType:@"jpg"]];
photo.caption = @"The London Eye is a giant Ferris wheel situated on the banks of the River Thames, in London, England.";
[photos addObject:photo];
}
else if(indexPath.section == 1) // Multiple photos
{
if(indexPath.row == 0) // Local Photos
{
photo = [IDMPhoto photoWithFilePath:[[NSBundle mainBundle] pathForResource:@"photo1l" ofType:@"jpg"]];
photo.caption = @"Grotto of the Madonna";
[photos addObject:photo];
photo = [IDMPhoto photoWithFilePath:[[NSBundle mainBundle] pathForResource:@"a" ofType:@"gif"]];
photo.caption = @"The London Eye is a giant Ferris wheel situated on the banks of the River Thames, in London, England.";
[photos addObject:photo];
photo = [IDMPhoto photoWithFilePath:[[NSBundle mainBundle] pathForResource:@"photo3l" ofType:@"jpg"]];
photo.caption = @"York Floods";
[photos addObject:photo];
photo = [IDMPhoto photoWithFilePath:[[NSBundle mainBundle] pathForResource:@"photo4l" ofType:@"jpg"]];
photo.caption = @"Campervan";
[photos addObject:photo];
}
else if(indexPath.row == 1 || indexPath.row == 2) // Photos from Flickr or Flickr - Custom
{
NSArray *photosWithURL = [IDMPhoto photosWithURLs:[NSArray arrayWithObjects:[NSURL URLWithString:@"http://farm4.static.flickr.com/3567/3523321514_371d9ac42f_b.jpg"], @"http://farm4.static.flickr.com/3629/3339128908_7aecabc34b_b.jpg", [NSURL URLWithString:@"http://farm4.static.flickr.com/3364/3338617424_7ff836d55f_b.jpg"], @"http://farm4.static.flickr.com/3590/3329114220_5fbc5bc92b_b.jpg", nil]];
photos = [NSMutableArray arrayWithArray:photosWithURL];
}
}
// Create and setup browser
IDMPhotoBrowser *browser = [[IDMPhotoBrowser alloc] initWithPhotos:photos];
browser.delegate = self;
if(indexPath.section == 1) // Multiple photos
{
if(indexPath.row == 1) // Photos from Flickr
{
browser.displayCounterLabel = YES;
browser.displayActionButton = NO;
}
else if(indexPath.row == 2) // Photos from Flickr - Custom
{
browser.actionButtonTitles = @[@"Option 1", @"Option 2", @"Option 3", @"Option 4"];
browser.displayCounterLabel = YES;
browser.useWhiteBackgroundColor = YES;
browser.leftArrowImage = [UIImage imageNamed:@"IDMPhotoBrowser_customArrowLeft.png"];
browser.rightArrowImage = [UIImage imageNamed:@"IDMPhotoBrowser_customArrowRight.png"];
browser.leftArrowSelectedImage = [UIImage imageNamed:@"IDMPhotoBrowser_customArrowLeftSelected.png"];
browser.rightArrowSelectedImage = [UIImage imageNamed:@"IDMPhotoBrowser_customArrowRightSelected.png"];
browser.doneButtonImage = [UIImage imageNamed:@"IDMPhotoBrowser_customDoneButton.png"];
browser.view.tintColor = [UIColor orangeColor];
browser.progressTintColor = [UIColor orangeColor];
browser.trackTintColor = [UIColor colorWithWhite:0.8 alpha:1];
}
}
// Show
[self presentViewController:browser animated:YES completion:nil];
[self.tableView deselectRowAtIndexPath:indexPath animated:YES];
}
#pragma mark - IDMPhotoBrowser Delegate
- (void)photoBrowser:(IDMPhotoBrowser *)photoBrowser didShowPhotoAtIndex:(NSUInteger)pageIndex
{
id <IDMPhoto> photo = [photoBrowser photoAtIndex:pageIndex];
NSLog(@"Did show photoBrowser with photo index: %zu, photo caption: %@", pageIndex, photo.caption);
}
- (void)photoBrowser:(IDMPhotoBrowser *)photoBrowser willDismissAtPageIndex:(NSUInteger)pageIndex
{
id <IDMPhoto> photo = [photoBrowser photoAtIndex:pageIndex];
NSLog(@"Will dismiss photoBrowser with photo index: %zu, photo caption: %@", pageIndex, photo.caption);
}
- (void)photoBrowser:(IDMPhotoBrowser *)photoBrowser didDismissAtPageIndex:(NSUInteger)pageIndex
{
id <IDMPhoto> photo = [photoBrowser photoAtIndex:pageIndex];
NSLog(@"Did dismiss photoBrowser with photo index: %zu, photo caption: %@", pageIndex, photo.caption);
}
- (void)photoBrowser:(IDMPhotoBrowser *)photoBrowser didDismissActionSheetWithButtonIndex:(NSUInteger)buttonIndex photoIndex:(NSUInteger)photoIndex
{
id <IDMPhoto> photo = [photoBrowser photoAtIndex:photoIndex];
NSLog(@"Did dismiss actionSheet with photo index: %zu, photo caption: %@", photoIndex, photo.caption);
NSString *title = [NSString stringWithFormat:@"Option %zu", buttonIndex+1];
[UIAlertView showAlertViewWithTitle:title];
}
@end