-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathImageDetailsViewController.m
206 lines (175 loc) · 6.64 KB
/
ImageDetailsViewController.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
//
// ImageDetailsViewController.m
// Virtual Gallery
//
// Created by Bratislav Ljubisic on 24/12/2012.
// Copyright (c) 2012 Gtech Beograd. All rights reserved.
//
#import "ImageDetailsViewController.h"
@interface ImageDetailsViewController () {
BOOL shownOverlay;
int startX;
int startY;
}
@end
@implementation ImageDetailsViewController
@synthesize delegate;
@synthesize imageView;
@synthesize image;
@synthesize model;
@synthesize imageScrollView;
@synthesize shareToolbar;
@synthesize detailsView;
@synthesize aperture;
@synthesize iso;
@synthesize camera;
@synthesize licence;
@synthesize exposure;
@synthesize name;
@synthesize focalLength;
@synthesize authorFirstName;
@synthesize authorLastName;
@synthesize authorImage;
@synthesize description;
@synthesize spinner;
@synthesize tempImage;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
[model setDelegate:self];
shownOverlay = NO;
/*
NSURL * tmpURLImage = [NSURL URLWithString:image.imageURLLarge];
NSData * imageData = [NSData dataWithContentsOfURL:tmpURLImage];
*/
imageView.image = tempImage;
UITapGestureRecognizer *tapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(touchImage:)];
[tapRecognizer setDelegate:self];
//CGRect imageViewFrame = imageView.frame;
//imageViewFrame.size.width = imageView.image.size.width;
//imageViewFrame.size.height = imageView.image.size.height;
//NSLog(@"image size: %f:%f", imageView.image.size.width, imageView.image.size.height);
//NSLog(@"image view size: %f:%f", imageView.frame.size.width, imageView.frame.size.height);
//[imageView setFrame:imageViewFrame];
//NSLog(@"image view size: %f:%f", imageView.frame.size.width, imageView.frame.size.height);
//self.imageScrollView.contentSize = imageView.image.size;
self.imageScrollView.delegate = self;
self.imageScrollView.minimumZoomScale = 1.0;
self.imageScrollView.maximumZoomScale = 10.0;
[self.imageScrollView setShowsHorizontalScrollIndicator:NO];
self.imageScrollView.showsVerticalScrollIndicator = NO;
self.name.text = self.image.title;
[self.view bringSubviewToFront:imageScrollView];
[self.view bringSubviewToFront:detailsView];
authorFirstName.text = self.image.authorFirstName;
authorLastName.text = self.image.authorLastName;
description.text = self.image.description;
NSURL *tmpAuthorImgUrl = [NSURL URLWithString:self.image.authorPicUrl];
NSData *authorImgData = [NSData dataWithContentsOfURL:tmpAuthorImgUrl];
authorImage.image = [[UIImage alloc] initWithData:authorImgData];
UIPanGestureRecognizer *panRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(move:)];
[panRecognizer setMinimumNumberOfTouches:1];
[panRecognizer setMaximumNumberOfTouches:1];
[panRecognizer setDelegate:self];
[model getImageInfo:image];
if([self.image.origin intValue] == 1)
[model getImageExif:self.image];
[detailsView addGestureRecognizer:panRecognizer];
[imageScrollView addGestureRecognizer:(UITapGestureRecognizer *) tapRecognizer];
[spinner stopAnimating];
}
- (UIView*)viewForZoomingInScrollView:(UIScrollView *)scrollView
{
return self.imageView;
}
- (void) touchImage:(id) sender {
if(!shownOverlay) {
shareToolbar.hidden = NO;
detailsView.hidden = NO;
detailsView.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.5f];
[self.view bringSubviewToFront:detailsView];
[self.view bringSubviewToFront:shareToolbar];
shownOverlay = YES;
}
else {
shareToolbar.hidden = YES;
detailsView.hidden = YES;
shownOverlay = NO;
}
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (void)viewDidUnload {
[self setImageView:nil];
[self setView:nil];
[super viewDidUnload];
}
- (IBAction)doneTouched:(id)sender {
if ([delegate respondsToSelector:@selector(doneButtonPressed)]) {
[delegate doneButtonPressed];
}
}
-(void) imageInfoReceived:(ImageObject *) photo {
authorFirstName.text = photo.authorFirstName;
authorLastName.text = photo.authorLastName;
description.text = photo.description;
NSURL *tmpAuthorImgUrl = [NSURL URLWithString:photo.authorPicUrl];
NSData *authorImgData = [NSData dataWithContentsOfURL:tmpAuthorImgUrl];
authorImage.image = [[UIImage alloc] initWithData:authorImgData];
self.image = photo;
[model getImageExif:image];
}
- (void) imageInfoExifReceived: (ImageObject *) photo {
if(photo.aperture != nil)
aperture.text = photo.aperture;
if(photo.iso != nil)
iso.text = photo.iso;
if(photo.exposure != nil)
exposure.text = photo.exposure;
if(photo.camera != nil)
camera.text = photo.camera;
if(photo.title != nil)
name.text = photo.title;
if(photo.focalLength != nil)
focalLength.text = photo.focalLength;
}
-(void)move:(id)sender {
UIPanGestureRecognizer *recognizer = (UIPanGestureRecognizer *) sender;
CGPoint translatedPoint = [recognizer translationInView:detailsView];
//NSLog(@"new central point is: %f %f", translatedPoint.x, translatedPoint.y);
// [self viewIntersectsWithAnotherView:[sender view]];
if([recognizer state] == UIGestureRecognizerStateBegan) {
startX = [[sender view] center].x;
startY = [[sender view] center].y;
}
translatedPoint = CGPointMake(startX, startY + translatedPoint.y);
[[sender view] setCenter:translatedPoint];
}
- (IBAction)pressedShareButton:(id)sender {
NSArray *activityItems;
NSString *postText = @"Seen on #virtualgallery: ";
postText = [postText stringByAppendingString:image.title];
postText = [postText stringByAppendingString:@" by "];
postText = [postText stringByAppendingString:image.author];
NSURL *sentURL = [NSURL URLWithString:image.imageURL];
activityItems = @[postText, sentURL];
UIActivityViewController *activityController =
[[UIActivityViewController alloc]
initWithActivityItems:activityItems
applicationActivities:nil];
activityController.excludedActivityTypes = @[UIActivityTypeAssignToContact, UIActivityTypeCopyToPasteboard, UIActivityTypePrint, UIActivityTypeSaveToCameraRoll];
[self presentViewController:activityController
animated:YES completion:nil];
}
@end