Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Refactoring toward adding a map.

  • Loading branch information...
commit 971e09d3439668f1df305f9ec0d3595049a5850b 1 parent fac2e1a
Sam Corder authored
8 BluesFest.xcodeproj/project.pbxproj
@@ -121,6 +121,8 @@
121 121 09A117C5155AC9BE0028B08E /* CBFBandImageHelper.m in Sources */ = {isa = PBXBuildFile; fileRef = 09A117C3155AC9BE0028B08E /* CBFBandImageHelper.m */; };
122 122 09A117CB155B68BA0028B08E /* ImageData.plist in Resources */ = {isa = PBXBuildFile; fileRef = 09A117CA155B68BA0028B08E /* ImageData.plist */; };
123 123 09A117CC155B68BA0028B08E /* ImageData.plist in Resources */ = {isa = PBXBuildFile; fileRef = 09A117CA155B68BA0028B08E /* ImageData.plist */; };
  124 + 09A117DB155CBD860028B08E /* CBFImageViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 09A117DA155CBD850028B08E /* CBFImageViewController.m */; };
  125 + 09A117DC155CBD860028B08E /* CBFImageViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 09A117DA155CBD850028B08E /* CBFImageViewController.m */; };
124 126 /* End PBXBuildFile section */
125 127
126 128 /* Begin PBXFileReference section */
@@ -235,6 +237,8 @@
235 237 09A117C2155AC9BE0028B08E /* CBFBandImageHelper.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CBFBandImageHelper.h; sourceTree = "<group>"; };
236 238 09A117C3155AC9BE0028B08E /* CBFBandImageHelper.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CBFBandImageHelper.m; sourceTree = "<group>"; };
237 239 09A117CA155B68BA0028B08E /* ImageData.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = ImageData.plist; sourceTree = "<group>"; };
  240 + 09A117D9155CBD820028B08E /* CBFImageViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; path = CBFImageViewController.h; sourceTree = "<group>"; };
  241 + 09A117DA155CBD850028B08E /* CBFImageViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CBFImageViewController.m; sourceTree = "<group>"; };
238 242 /* End PBXFileReference section */
239 243
240 244 /* Begin PBXFrameworksBuildPhase section */
@@ -324,6 +328,8 @@
324 328 091BA3D2155A08B900C94F95 /* CBFShowDetailNavHelper.m */,
325 329 0960F5451551AA3C0083C9C8 /* CBFShowImageViewController.h */,
326 330 0960F5461551AA3D0083C9C8 /* CBFShowImageViewController.m */,
  331 + 09A117D9155CBD820028B08E /* CBFImageViewController.h */,
  332 + 09A117DA155CBD850028B08E /* CBFImageViewController.m */,
327 333 0960F506154E3F7D0083C9C8 /* CBFAgendaTableViewController.h */,
328 334 0960F507154E3F7D0083C9C8 /* CBFAgendaTableViewController.m */,
329 335 0949366B154BA3A40062F2AB /* CBFShowTableViewController.h */,
@@ -623,6 +629,7 @@
623 629 091BA3CF1559B57500C94F95 /* CoreDataTableViewController.m in Sources */,
624 630 091BA3D3155A08B900C94F95 /* CBFShowDetailNavHelper.m in Sources */,
625 631 09A117C4155AC9BE0028B08E /* CBFBandImageHelper.m in Sources */,
  632 + 09A117DB155CBD860028B08E /* CBFImageViewController.m in Sources */,
626 633 );
627 634 runOnlyForDeploymentPostprocessing = 0;
628 635 };
@@ -668,6 +675,7 @@
668 675 091BA3D01559B57500C94F95 /* CoreDataTableViewController.m in Sources */,
669 676 091BA3D4155A08B900C94F95 /* CBFShowDetailNavHelper.m in Sources */,
670 677 09A117C5155AC9BE0028B08E /* CBFBandImageHelper.m in Sources */,
  678 + 09A117DC155CBD860028B08E /* CBFImageViewController.m in Sources */,
671 679 );
672 680 runOnlyForDeploymentPostprocessing = 0;
673 681 };
4 BluesFest/CBFBandImageHelper.m
@@ -20,9 +20,9 @@ +(NSURL *)imageUrlFor:(NSString *)pic OfSize:(NSNumber *)size
20 20 pic = [path stringByAppendingFormat:@"_thumb_%d%@",([size intValue] * scale),ext];
21 21
22 22 }
  23 + NSString *base = @"http://192.168.1.143:4567/band/images/";
23 24
24   -
25   - NSString *base = @"http://10.129.74.116:4567/band/images/";
  25 + //NSString *base = @"http://10.129.74.116:4567/band/images/";
26 26 NSString *urlstr = [base stringByAppendingString:[pic stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
27 27
28 28
3  BluesFest/CBFFestDataController.m
@@ -23,7 +23,8 @@ @implementation CBFFestDataController
23 23 -(CBFFestDataController *)initWithManagedObjectContext:(NSManagedObjectContext *)context
24 24 {
25 25 moc = context;
26   - httpClient = [AFHTTPClient clientWithBaseURL:[NSURL URLWithString:@"http://10.129.74.116:4567/"]];
  26 + //httpClient = [AFHTTPClient clientWithBaseURL:[NSURL URLWithString:@"http://10.129.74.116:4567/"]];
  27 + httpClient = [AFHTTPClient clientWithBaseURL:[NSURL URLWithString:@"http://192.168.1.143:4567/"]];
27 28
28 29 return self;
29 30 }
9 BluesFest/CBFImageScrollView.h
@@ -7,19 +7,24 @@
7 7 //
8 8
9 9 #import <UIKit/UIKit.h>
  10 +#import "CBFTilingView.h"
10 11
11 12 @interface CBFImageScrollView : UIScrollView <UIScrollViewDelegate> {
12   - UIView *imageView;
13 13 NSUInteger index;
14 14 }
15 15 @property (assign) NSUInteger index;
  16 +@property (strong,nonatomic) UIView *imageView;
  17 +@property (strong,nonatomic) id<CBFTilingViewDelegate> tilingDelegate;
  18 +
  19 +- (id)initWithFrame:(CGRect)frame;
16 20
17 21 - (void)displayImage:(UIImage *)image;
18   -//- (void)displayTiledImageNamed:(NSString *)imageName size:(CGSize)imageSize;
  22 +- (void)displayTiledImageNamed:(NSString *)imageName size:(CGSize)imageSize;
19 23 - (void)setMaxMinZoomScalesForCurrentBounds;
20 24
21 25 - (CGPoint)pointToCenterAfterRotation;
22 26 - (CGFloat)scaleToRestoreAfterRotation;
23 27 - (void)restoreCenterPoint:(CGPoint)oldCenter scale:(CGFloat)oldScale;
24 28
  29 +
25 30 @end
73 BluesFest/CBFImageScrollView.m
... ... @@ -1,10 +1,11 @@
1 1
2 2
3 3 #import "CBFImageScrollView.h"
4   -#import "CBFTilingView.h"
5 4
6 5 @implementation CBFImageScrollView
7 6 @synthesize index;
  7 +@synthesize imageView = _imageView;
  8 +@synthesize tilingDelegate = _tilingDelegate;
8 9
9 10 - (id)initWithFrame:(CGRect)frame
10 11 {
@@ -20,7 +21,7 @@ - (id)initWithFrame:(CGRect)frame
20 21
21 22 - (void)dealloc
22 23 {
23   - imageView = nil;
  24 + _imageView = nil;
24 25 }
25 26
26 27 - (void)layoutSubviews
@@ -30,7 +31,7 @@ - (void)layoutSubviews
30 31 // center the image as it becomes smaller than the size of the screen
31 32
32 33 CGSize boundsSize = self.bounds.size;
33   - CGRect frameToCenter = imageView.frame;
  34 + CGRect frameToCenter = _imageView.frame;
34 35
35 36 // center horizontally
36 37 if (frameToCenter.size.width < boundsSize.width)
@@ -44,14 +45,8 @@ - (void)layoutSubviews
44 45 else
45 46 frameToCenter.origin.y = 0;
46 47
47   - imageView.frame = frameToCenter;
48   -
49   - if ([imageView isKindOfClass:[CBFTilingView class]]) {
50   - // to handle the interaction between CATiledLayer and high resolution screens, we need to manually set the
51   - // tiling view's contentScaleFactor to 1.0. (If we omitted this, it would be 2.0 on high resolution screens,
52   - // which would cause the CATiledLayer to ask us for tiles of the wrong scales.)
53   - imageView.contentScaleFactor = 1.0;
54   - }
  48 + self.imageView.frame = frameToCenter;
  49 +
55 50 }
56 51
57 52 #pragma mark -
@@ -59,7 +54,7 @@ - (void)layoutSubviews
59 54
60 55 - (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView
61 56 {
62   - return imageView;
  57 + return self.imageView;
63 58 }
64 59
65 60 #pragma mark -
@@ -68,44 +63,48 @@ - (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView
68 63 - (void)displayImage:(UIImage *)image
69 64 {
70 65 // clear the previous imageView
71   - [imageView removeFromSuperview];
72   - imageView = nil;
  66 + [self.imageView removeFromSuperview];
  67 + self.imageView = nil;
73 68
74 69 // reset our zoomScale to 1.0 before doing any further calculations
75 70 self.zoomScale = 1.0;
76 71
77 72 // make a new UIImageView for the new image
78   - imageView = [[UIImageView alloc] initWithImage:image];
79   - [self addSubview:imageView];
  73 + self.imageView = [[UIImageView alloc] initWithImage:image];
  74 +
  75 + [self addSubview:self.imageView];
80 76
81 77 self.contentSize = [image size];
82 78 [self setMaxMinZoomScalesForCurrentBounds];
83 79 self.zoomScale = self.minimumZoomScale;
84 80 }
85 81
86   -//- (void)displayTiledImageNamed:(NSString *)imageName size:(CGSize)imageSize
87   -//{
88   -// // clear the previous imageView
89   -// [imageView removeFromSuperview];
90   -// imageView = nil;
91   -//
92   -// // reset our zoomScale to 1.0 before doing any further calculations
93   -// self.zoomScale = 1.0;
94   -//
95   -// // make a new TilingView for the new image
96   -// imageView = [[CBFTilingView alloc] initWithImageName:imageName size:imageSize];
97   -// [(CBFTilingView *)imageView setAnnotates:YES]; // ** remove this line to remove the white tile grid **
98   -// [self addSubview:imageView];
99   -//
100   -// self.contentSize = imageSize;
101   -// [self setMaxMinZoomScalesForCurrentBounds];
102   -// self.zoomScale = self.minimumZoomScale;
103   -//}
  82 +- (void)displayTiledImageNamed:(NSString *)imageName size:(CGSize)imageSize
  83 +{
  84 + // clear the previous imageView
  85 + [_imageView removeFromSuperview];
  86 + _imageView = nil;
  87 +
  88 + // reset our zoomScale to 1.0 before doing any further calculations
  89 + self.zoomScale = 1.0;
  90 +
  91 + // make a new TilingView for the new image
  92 + CBFTilingView *imageView = [[CBFTilingView alloc] initWithImageName:imageName size:imageSize];
  93 + imageView.delegate = self.tilingDelegate;
  94 +
  95 + [imageView setAnnotates:YES]; // ** remove this line to remove the white tile grid **
  96 + _imageView = imageView;
  97 + [self addSubview:imageView];
  98 +
  99 + self.contentSize = imageSize;
  100 + [self setMaxMinZoomScalesForCurrentBounds];
  101 + self.zoomScale = self.minimumZoomScale;
  102 +}
104 103
105 104 - (void)setMaxMinZoomScalesForCurrentBounds
106 105 {
107 106 CGSize boundsSize = self.bounds.size;
108   - CGSize imageSize = imageView.bounds.size;
  107 + CGSize imageSize = _imageView.bounds.size;
109 108
110 109 // calculate min/max zoomscale
111 110 CGFloat xScale = boundsSize.width / imageSize.width; // the scale needed to perfectly fit the image width-wise
@@ -132,7 +131,7 @@ - (void)setMaxMinZoomScalesForCurrentBounds
132 131 - (CGPoint)pointToCenterAfterRotation
133 132 {
134 133 CGPoint boundsCenter = CGPointMake(CGRectGetMidX(self.bounds), CGRectGetMidY(self.bounds));
135   - return [self convertPoint:boundsCenter toView:imageView];
  134 + return [self convertPoint:boundsCenter toView:_imageView];
136 135 }
137 136
138 137 // returns the zoom scale to attempt to restore after rotation.
@@ -171,7 +170,7 @@ - (void)restoreCenterPoint:(CGPoint)oldCenter scale:(CGFloat)oldScale
171 170 // Step 2: restore center point, first making sure it is within the allowable range.
172 171
173 172 // 2a: convert our desired center point back to our own coordinate space
174   - CGPoint boundsCenter = [self convertPoint:oldCenter fromView:imageView];
  173 + CGPoint boundsCenter = [self convertPoint:oldCenter fromView:_imageView];
175 174 // 2b: calculate the content offset that would yield that center point
176 175 CGPoint offset = CGPointMake(boundsCenter.x - self.bounds.size.width / 2.0,
177 176 boundsCenter.y - self.bounds.size.height / 2.0);
18 BluesFest/CBFImageViewController.h
... ... @@ -0,0 +1,18 @@
  1 +//
  2 +// CBFImageViewControllerViewController.h
  3 +// BluesFest
  4 +//
  5 +// Created by Sam Corder on 5/10/12.
  6 +// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
  7 +//
  8 +
  9 +#import <UIKit/UIKit.h>
  10 +
  11 +#import "CBFImageScrollView.h"
  12 +
  13 +@interface CBFImageViewController : UIViewController<UIScrollViewDelegate> {
  14 +}
  15 +@property(strong,nonatomic) CBFImageScrollView *scrollView;
  16 +- (IBAction)doneSelected:(UIBarButtonItem *)sender;
  17 +
  18 +@end
127 BluesFest/CBFImageViewController.m
... ... @@ -0,0 +1,127 @@
  1 +//
  2 +// CBFImageViewControllerViewController.m
  3 +// BluesFest
  4 +//
  5 +// Created by Sam Corder on 5/10/12.
  6 +// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
  7 +//
  8 +
  9 +#import "CBFImageViewController.h"
  10 +
  11 +@interface CBFImageViewController ()
  12 +{
  13 + UIStatusBarStyle lastStyle;
  14 +}
  15 +
  16 +@end
  17 +
  18 +@implementation CBFImageViewController
  19 +@synthesize scrollView = _scrollView;
  20 +
  21 +- (void)loadView
  22 +{
  23 + [super loadView];
  24 + CGRect frame = [UIScreen mainScreen].bounds;
  25 +
  26 + UIView *container = [[UIView alloc]initWithFrame:frame];
  27 + self.view = container;
  28 +
  29 + _scrollView = [[CBFImageScrollView alloc]initWithFrame:frame];
  30 +
  31 + _scrollView.backgroundColor = [UIColor blackColor];
  32 + _scrollView.showsVerticalScrollIndicator = NO;
  33 + _scrollView.showsHorizontalScrollIndicator = NO;
  34 + _scrollView.bounces = YES;
  35 + _scrollView.bouncesZoom = YES;
  36 + _scrollView.delegate = self;
  37 +
  38 + [container addSubview:_scrollView];
  39 +
  40 + CGRect navFrame = CGRectMake(0, 20.0, frame.size.width, 44);
  41 + UINavigationBar *nav = [[UINavigationBar alloc]initWithFrame:navFrame];
  42 + nav.translucent = YES;
  43 + nav.tintColor = [UIColor blackColor];
  44 +
  45 + UIBarButtonItem *done = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(doneSelected:)];
  46 +
  47 + UINavigationItem *doneIt = [[UINavigationItem alloc]init];
  48 + [doneIt setRightBarButtonItem:done animated:YES];
  49 +
  50 + [nav pushNavigationItem:doneIt animated:YES];
  51 +
  52 + [container addSubview:nav];
  53 +
  54 +}
  55 +
  56 +- (void)viewDidLoad
  57 +{
  58 + [super viewDidLoad];
  59 + // Do any additional setup after loading the view.
  60 +}
  61 +
  62 +-(void)viewWillAppear:(BOOL)animated
  63 +{
  64 + lastStyle = [UIApplication sharedApplication].statusBarStyle;
  65 + [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleBlackTranslucent animated:YES];
  66 +}
  67 +
  68 +-(void)viewWillDisappear:(BOOL)animated
  69 +{
  70 + [[UIApplication sharedApplication] setStatusBarStyle:lastStyle animated:YES];
  71 +}
  72 +- (void)viewDidUnload
  73 +{
  74 + [super viewDidUnload];
  75 + // Release any retained subviews of the main view.
  76 +}
  77 +
  78 +
  79 +#pragma mark -
  80 +#pragma mark ScrollView delegate methods
  81 +- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView
  82 +{
  83 + return ((CBFImageScrollView *)scrollView).imageView;
  84 +}
  85 +
  86 +- (void)scrollViewDidZoom:(UIScrollView *)scrollView {
  87 + UIView *image = ((CBFImageScrollView *)scrollView).imageView;
  88 +
  89 + image.frame = [self centeredFrameForScrollView:scrollView andUIView:image];
  90 +}
  91 +
  92 +
  93 +-(CGRect)centeredFrameForScrollView:(UIScrollView *)scroll andUIView:(UIView *)rView {
  94 + CGSize boundsSize = scroll.bounds.size;
  95 + CGRect frameToCenter = rView.frame;
  96 + // center horizontally
  97 + if (frameToCenter.size.width < boundsSize.width) {
  98 + frameToCenter.origin.x = (boundsSize.width - frameToCenter.size.width) / 2;
  99 + }
  100 + else {
  101 + frameToCenter.origin.x = 0;
  102 + }
  103 + // center vertically
  104 + if (frameToCenter.size.height < boundsSize.height) {
  105 + frameToCenter.origin.y = (boundsSize.height - frameToCenter.size.height) / 2;
  106 + }
  107 + else {
  108 + frameToCenter.origin.y = 0;
  109 + }
  110 + return frameToCenter;
  111 +}
  112 +
  113 +- (void)scrollViewDidScroll:(UIScrollView *)scrollView
  114 +{
  115 +
  116 +}
  117 +
  118 +#pragma mark -
  119 +#pragma mark View controller rotation methods
  120 +
  121 +- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
  122 +{
  123 + return YES;
  124 +}
  125 +
  126 +
  127 +@end
6 BluesFest/CBFShowDetailViewController.m
@@ -15,6 +15,7 @@
15 15 #import "UILabel+CBFUILabelSizeToFitFixedWidth.h"
16 16 #import "CBFCurvedAnimator.h"
17 17 #import "CBFBandImageHelper.h"
  18 +#import "CBFShowImageViewController.h"
18 19
19 20 @interface CBFShowDetailViewController (){
20 21 UIImage *staroff;
@@ -217,6 +218,11 @@ -(void)animateSwipe:(NSString *)direction
217 218 -(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
218 219 {
219 220 NSLog(@"Segueing out of show detail view controller");
  221 + if([segue.identifier isEqualToString:@"Show Image Segue"]){
  222 + CBFShowImageViewController *controller = (CBFShowImageViewController *)segue.destinationViewController;
  223 +
  224 + controller.band = self.show.band;
  225 + }
220 226 }
221 227
222 228 @end
27 BluesFest/CBFShowImageViewController.h
@@ -7,34 +7,17 @@
7 7 //
8 8
9 9 #import <UIKit/UIKit.h>
  10 +#import "CBFImageViewController.h"
10 11 #import "CBFImageScrollView.h"
11 12
12   -@interface CBFShowImageViewController : UIViewController <UIScrollViewDelegate> {
  13 +#import "models.h"
13 14
14   -UIScrollView *pagingScrollView;
  15 +@interface CBFShowImageViewController : CBFImageViewController {
15 16
16   -NSMutableSet *recycledPages;
17   -NSMutableSet *visiblePages;
18   -
19   -// these values are stored off before we start rotation so we adjust our content offset appropriately during rotation
20   -int firstVisiblePageIndexBeforeRotation;
21   -CGFloat percentScrolledIntoFirstVisiblePage;
22 17 }
23 18
24   -- (void)configurePage:(CBFImageScrollView *)page forIndex:(NSUInteger)index;
25   -- (BOOL)isDisplayingPageForIndex:(NSUInteger)index;
26   -
27   -- (CGRect)frameForPagingScrollView;
28   -- (CGRect)frameForPageAtIndex:(NSUInteger)index;
29   -- (CGSize)contentSizeForPagingScrollView;
30   -
31   -- (void)tilePages;
32   -- (CBFImageScrollView *)dequeueRecycledPage;
  19 +@property (strong, nonatomic) Band *band;
33 20
34   -@property (strong, nonatomic)NSArray *imageList;
  21 +- (IBAction)doneSelected:(UIBarButtonItem *)sender;
35 22
36   -- (NSUInteger)imageCount;
37   -//- (NSString *)imageNameAtIndex:(NSUInteger)index;
38   -//- (CGSize)imageSizeAtIndex:(NSUInteger)index;
39   -//- (UIImage *)imageAtIndex:(NSUInteger)index;
40 23 @end
265 BluesFest/CBFShowImageViewController.m
@@ -4,263 +4,44 @@
4 4
5 5 #import "CBFShowImageViewController.h"
6 6
  7 +#import "AFNetworking.h"
7 8
8   -@interface CBFShowImageViewController ()
  9 +#import "CBFBandImageHelper.h"
9 10
10   -@end
11   -
12   -@implementation CBFShowImageViewController
13   -
14   -@synthesize imageList = _imageList;
15   -
16   --(NSUInteger)imageCount
17   -{
18   - if(self.imageList == nil) return 0;
19   -
20   - return [self.imageList count];
  11 +@interface CBFShowImageViewController (){
  12 + AFHTTPClient *httpClient;
21 13 }
22 14
23   -- (void)loadView
24   -{
25   - // Step 1: make the outer paging scroll view
26   - CGRect pagingScrollViewFrame = [self frameForPagingScrollView];
27   - pagingScrollView = [[UIScrollView alloc] initWithFrame:pagingScrollViewFrame];
28   - pagingScrollView.pagingEnabled = YES;
29   - pagingScrollView.backgroundColor = [UIColor blackColor];
30   - pagingScrollView.showsVerticalScrollIndicator = NO;
31   - pagingScrollView.showsHorizontalScrollIndicator = NO;
32   - pagingScrollView.contentSize = [self contentSizeForPagingScrollView];
33   - pagingScrollView.delegate = self;
34   - self.view = pagingScrollView;
35   -
36   - // Step 2: prepare to tile content
37   - recycledPages = [[NSMutableSet alloc] init];
38   - visiblePages = [[NSMutableSet alloc] init];
39   - [self tilePages];
40   -}
41   -
42   -- (void)viewDidUnload
43   -{
44   - [super viewDidUnload];
45   - pagingScrollView = nil;
46   - recycledPages = nil;
47   - visiblePages = nil;
48   -}
49   -
50   -- (void)dealloc
51   -{
52   - pagingScrollView = nil;
53   -}
  15 +-(void)loadImage;
54 16
  17 +@end
55 18
56   -#pragma mark -
57   -#pragma mark Tiling and page configuration
58   -
59   -- (void)tilePages
60   -{
61   - // Calculate which pages are visible
62   - CGRect visibleBounds = pagingScrollView.bounds;
63   - int firstNeededPageIndex = floorf(CGRectGetMinX(visibleBounds) / CGRectGetWidth(visibleBounds));
64   - int lastNeededPageIndex = floorf((CGRectGetMaxX(visibleBounds)-1) / CGRectGetWidth(visibleBounds));
65   - firstNeededPageIndex = MAX(firstNeededPageIndex, 0);
66   - lastNeededPageIndex = MIN(lastNeededPageIndex, [self imageCount] - 1);
67   -
68   - // Recycle no-longer-visible pages
69   - for (CBFImageScrollView *page in visiblePages) {
70   - if (page.index < firstNeededPageIndex || page.index > lastNeededPageIndex) {
71   - [recycledPages addObject:page];
72   - [page removeFromSuperview];
73   - }
74   - }
75   - [visiblePages minusSet:recycledPages];
76   -
77   - // add missing pages
78   - for (int index = firstNeededPageIndex; index <= lastNeededPageIndex; index++) {
79   - if (![self isDisplayingPageForIndex:index]) {
80   - CBFImageScrollView *page = [self dequeueRecycledPage];
81   - if (page == nil) {
82   - page = [[CBFImageScrollView alloc] init];
83   - }
84   - [self configurePage:page forIndex:index];
85   - [pagingScrollView addSubview:page];
86   - [visiblePages addObject:page];
87   - }
88   - }
89   -}
90   -
91   -- (CBFImageScrollView *)dequeueRecycledPage
92   -{
93   - CBFImageScrollView *page = [recycledPages anyObject];
94   - if (page) {
95   - [recycledPages removeObject:page];
96   - }
97   - return page;
98   -}
99   -
100   -- (BOOL)isDisplayingPageForIndex:(NSUInteger)index
101   -{
102   - BOOL foundPage = NO;
103   - for (CBFImageScrollView *page in visiblePages) {
104   - if (page.index == index) {
105   - foundPage = YES;
106   - break;
107   - }
108   - }
109   - return foundPage;
110   -}
111   -
112   -- (void)configurePage:(CBFImageScrollView *)page forIndex:(NSUInteger)index
113   -{
114   - page.index = index;
115   - page.frame = [self frameForPageAtIndex:index];
116   -
117   - // Use tiled images
118   - //[page displayTiledImageNamed:[self imageNameAtIndex:index]
119   - // size:[self imageSizeAtIndex:index]];
120   -
121   - // To use full images instead of tiled images, replace the "displayTiledImageNamed:" call
122   - // above by the following line:
123   - [page displayImage:[self imageAtIndex:index]];
124   -}
125   -
126   -
127   -#pragma mark -
128   -#pragma mark ScrollView delegate methods
129   -
130   -- (void)scrollViewDidScroll:(UIScrollView *)scrollView
131   -{
132   - [self tilePages];
133   -}
134   -
135   -#pragma mark -
136   -#pragma mark View controller rotation methods
  19 +@implementation CBFShowImageViewController
137 20
138   -- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
  21 +@synthesize band = _band;
  22 +-(void)setBand:(Band *)band
139 23 {
140   - return YES;
141   -}
  24 + _band = band;
  25 + [self loadImage];
142 26
143   -- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
144   -{
145   - // here, our pagingScrollView bounds have not yet been updated for the new interface orientation. So this is a good
146   - // place to calculate the content offset that we will need in the new orientation
147   - CGFloat offset = pagingScrollView.contentOffset.x;
148   - CGFloat pageWidth = pagingScrollView.bounds.size.width;
149   -
150   - if (offset >= 0) {
151   - firstVisiblePageIndexBeforeRotation = floorf(offset / pageWidth);
152   - percentScrolledIntoFirstVisiblePage = (offset - (firstVisiblePageIndexBeforeRotation * pageWidth)) / pageWidth;
153   - } else {
154   - firstVisiblePageIndexBeforeRotation = 0;
155   - percentScrolledIntoFirstVisiblePage = offset / pageWidth;
156   - }
157 27 }
158 28
159   -- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
  29 +-(void)loadImage
160 30 {
161   - // recalculate contentSize based on current orientation
162   - pagingScrollView.contentSize = [self contentSizeForPagingScrollView];
  31 + NSURLRequest *request = [CBFBandImageHelper imageRequestFor:_band.pic OfSize:nil];
  32 +
  33 + NSLog(@"Requesting image %@", [request description]);
  34 + void (^success)(UIImage*);
163 35
164   - // adjust frames and configuration of each visible page
165   - for (CBFImageScrollView *page in visiblePages) {
166   - CGPoint restorePoint = [page pointToCenterAfterRotation];
167   - CGFloat restoreScale = [page scaleToRestoreAfterRotation];
168   - page.frame = [self frameForPageAtIndex:page.index];
169   - [page setMaxMinZoomScalesForCurrentBounds];
170   - [page restoreCenterPoint:restorePoint scale:restoreScale];
171   -
172   - }
  36 + success = ^(UIImage *image){
  37 + [self.scrollView displayImage:image];
  38 + };
173 39
174   - // adjust contentOffset to preserve page location based on values collected prior to location
175   - CGFloat pageWidth = pagingScrollView.bounds.size.width;
176   - CGFloat newOffset = (firstVisiblePageIndexBeforeRotation * pageWidth) + (percentScrolledIntoFirstVisiblePage * pageWidth);
177   - pagingScrollView.contentOffset = CGPointMake(newOffset, 0);
178   -}
179   -
180   -#pragma mark -
181   -#pragma mark Frame calculations
182   -#define PADDING 10
183   -
184   -- (CGRect)frameForPagingScrollView {
185   - CGRect frame = [[UIScreen mainScreen] bounds];
186   - frame.origin.x -= PADDING;
187   - frame.size.width += (2 * PADDING);
188   - return frame;
189   -}
190   -
191   -- (CGRect)frameForPageAtIndex:(NSUInteger)index {
192   - // We have to use our paging scroll view's bounds, not frame, to calculate the page placement. When the device is in
193   - // landscape orientation, the frame will still be in portrait because the pagingScrollView is the root view controller's
194   - // view, so its frame is in window coordinate space, which is never rotated. Its bounds, however, will be in landscape
195   - // because it has a rotation transform applied.
196   - CGRect bounds = pagingScrollView.bounds;
197   - CGRect pageFrame = bounds;
198   - pageFrame.size.width -= (2 * PADDING);
199   - pageFrame.origin.x = (bounds.size.width * index) + PADDING;
200   - return pageFrame;
  40 + AFImageRequestOperation *operation = [AFImageRequestOperation imageRequestOperationWithRequest:request success:success];
  41 + [operation start];
201 42 }
202 43
203   -- (CGSize)contentSizeForPagingScrollView {
204   - // We have to use the paging scroll view's bounds to calculate the contentSize, for the same reason outlined above.
205   - CGRect bounds = pagingScrollView.bounds;
206   - return CGSizeMake(bounds.size.width * [self imageCount], bounds.size.height);
207   -}
208   -
209   -
210   -#pragma mark -
211   -#pragma mark Image wrangling
212   -
213   -//- (NSArray *)imageData {
214   -// static NSArray *__imageData = nil; // only load the imageData array once
215   -// if (__imageData == nil) {
216   -// // read the filenames/sizes out of a plist in the app bundle
217   -// NSString *path = [[NSBundle mainBundle] pathForResource:@"ImageData" ofType:@"plist"];
218   -// NSData *plistData = [NSData dataWithContentsOfFile:path];
219   -// NSString *error; NSPropertyListFormat format;
220   -// __imageData = [NSPropertyListSerialization propertyListFromData:plistData
221   -// mutabilityOption:NSPropertyListImmutable
222   -// format:&format
223   -// errorDescription:&error];
224   -// if (!__imageData) {
225   -// NSLog(@"Failed to read image names. Error: %@", error);
226   -// }
227   -// }
228   -// return __imageData;
229   -//}
230   -
231   -- (UIImage *)imageAtIndex:(NSUInteger)index {
232   - // use "imageWithContentsOfFile:" instead of "imageNamed:" here to avoid caching our images
233   - NSString *imageName = [self.imageList objectAtIndex:index]; //[self imageNameAtIndex:index];
234   - NSString *path = [[NSBundle mainBundle] pathForResource:imageName ofType:@"jpg"];
235   - return [UIImage imageWithContentsOfFile:path];
  44 +- (IBAction)doneSelected:(UIBarButtonItem *)sender {
  45 + [self dismissModalViewControllerAnimated:YES];
236 46 }
237   -
238   -//- (NSString *)imageNameAtIndex:(NSUInteger)index {
239   -// NSString *name = nil;
240   -// if (index < [self imageCount]) {
241   -// NSDictionary *data = [[self imageData] objectAtIndex:index];
242   -// name = [data valueForKey:@"name"];
243   -// }
244   -// return name;
245   -//}
246   -
247   -//- (CGSize)imageSizeAtIndex:(NSUInteger)index {
248   -// CGSize size = CGSizeZero;
249   -// if (index < [self imageCount]) {
250   -// NSDictionary *data = [[self imageData] objectAtIndex:index];
251   -// size.width = [[data valueForKey:@"width"] floatValue];
252   -// size.height = [[data valueForKey:@"height"] floatValue];
253   -// }
254   -// return size;
255   -//}
256   -//
257   -//- (NSUInteger)imageCount {
258   -// static NSUInteger __count = NSNotFound; // only count the images once
259   -// if (__count == NSNotFound) {
260   -// __count = [[self imageData] count];
261   -// }
262   -// return __count;
263   -//}
264   -
265   -
266 47 @end
9 BluesFest/CBFShowMapViewController.m
@@ -16,15 +16,6 @@ @implementation CBFShowMapViewController
16 16
17 17 @synthesize managedObjectContext = _moc;
18 18
19   -- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
20   -{
21   - self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
22   - if (self) {
23   - // Custom initialization
24   - }
25   - return self;
26   -}
27   -
28 19 - (void)viewDidLoad
29 20 {
30 21 [super viewDidLoad];
8 BluesFest/CBFTilingView.h
@@ -8,13 +8,19 @@
8 8
9 9 #import <UIKit/UIKit.h>
10 10
  11 +@protocol CBFTilingViewDelegate <NSObject>
  12 +
  13 +- (UIImage *)tileForScale:(CGFloat)scale row:(int)row col:(int)col;
  14 +
  15 +@end
  16 +
11 17 @interface CBFTilingView : UIView{
12 18 NSString *imageName;
13 19 BOOL annotates;
14 20 }
15 21 @property (assign) BOOL annotates;
  22 +@property (strong, nonatomic) id<CBFTilingViewDelegate> delegate;
16 23
17 24 - (id)initWithImageName:(NSString *)name size:(CGSize)size;
18   -- (UIImage *)tileForScale:(CGFloat)scale row:(int)row col:(int)col;
19 25
20 26 @end
19 BluesFest/CBFTilingView.m
@@ -13,6 +13,7 @@
13 13
14 14 @implementation CBFTilingView
15 15 @synthesize annotates;
  16 +@synthesize delegate = _delegate;
16 17
17 18 + (Class)layerClass {
18 19 return [CATiledLayer class];
@@ -51,7 +52,7 @@ - (void)drawRect:(CGRect)rect {
51 52
52 53 for (int row = firstRow; row <= lastRow; row++) {
53 54 for (int col = firstCol; col <= lastCol; col++) {
54   - UIImage *tile = [self tileForScale:scale row:row col:col];
  55 + UIImage *tile = [self.delegate tileForScale:scale row:row col:col];
55 56 CGRect tileRect = CGRectMake(tileSize.width * col, tileSize.height * row,
56 57 tileSize.width, tileSize.height);
57 58
@@ -70,14 +71,14 @@ - (void)drawRect:(CGRect)rect {
70 71 }
71 72 }
72 73
73   -- (UIImage *)tileForScale:(CGFloat)scale row:(int)row col:(int)col
74   -{
75   - // we use "imageWithContentsOfFile:" instead of "imageNamed:" here because we don't want UIImage to cache our tiles
76   - NSString *tileName = [NSString stringWithFormat:@"%@_%d_%d_%d", imageName, (int)(scale * 1000), col, row];
77   - NSString *path = [[NSBundle mainBundle] pathForResource:tileName ofType:@"png"];
78   - UIImage *image = [UIImage imageWithContentsOfFile:path];
79   - return image;
80   -}
  74 +//- (UIImage *)tileForScale:(CGFloat)scale row:(int)row col:(int)col
  75 +//{
  76 +// // we use "imageWithContentsOfFile:" instead of "imageNamed:" here because we don't want UIImage to cache our tiles
  77 +// NSString *tileName = [NSString stringWithFormat:@"%@_%d_%d_%d", imageName, (int)(scale * 1000), col, row];
  78 +// NSString *path = [[NSBundle mainBundle] pathForResource:tileName ofType:@"png"];
  79 +// UIImage *image = [UIImage imageWithContentsOfFile:path];
  80 +// return image;
  81 +//}
81 82
82 83
83 84
22 BluesFest/main-iphone.storyboard
@@ -385,7 +385,7 @@
385 385 </swipeGestureRecognizer>
386 386 <tapGestureRecognizer id="XXz-RZ-UAR">
387 387 <connections>
388   - <segue destination="P7x-CB-8Jb" kind="push" identifier="Show Image" id="IRv-Ex-aRp"/>
  388 + <segue destination="P7x-CB-8Jb" kind="modal" identifier="Show Image Segue" modalTransitionStyle="coverVertical" id="IRv-Ex-aRp"/>
389 389 </connections>
390 390 </tapGestureRecognizer>
391 391 </objects>
@@ -395,16 +395,19 @@
395 395 <scene sceneID="wNh-SJ-Efs">
396 396 <objects>
397 397 <placeholder placeholderIdentifier="IBFirstResponder" id="HL1-fq-BrX" userLabel="First Responder" sceneMemberID="firstResponder"/>
398   - <viewController id="P7x-CB-8Jb" customClass="CBFShowImageViewController" sceneMemberID="viewController">
399   - <view key="view" contentMode="scaleToFill" id="bW6-K7-Hld">
  398 + <viewController autoresizesArchivedViewToFullSize="NO" wantsFullScreenLayout="YES" modalTransitionStyle="crossDissolve" id="P7x-CB-8Jb" customClass="CBFShowImageViewController" sceneMemberID="viewController">
  399 + <view key="view" contentMode="scaleToFill" id="7R6-11-b3H">
400 400 <rect key="frame" x="0.0" y="0.0" width="320" height="460"/>
401   - <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
402   - <color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
  401 + <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
  402 + <color key="backgroundColor" white="0.0" alpha="1" colorSpace="calibratedWhite"/>
403 403 </view>
404   - <navigationItem key="navigationItem" id="4Og-sn-n2a"/>
  404 + <toolbarItems/>
  405 + <nil key="simulatedStatusBarMetrics"/>
  406 + <nil key="simulatedBottomBarMetrics"/>
  407 + <simulatedOrientationMetrics key="simulatedOrientationMetrics"/>
405 408 </viewController>
406 409 </objects>
407   - <point key="canvasLocation" x="1062" y="-6"/>
  410 + <point key="canvasLocation" x="1061" y="-12"/>
408 411 </scene>
409 412 <!--Managed Nav View Controller-->
410 413 <scene sceneID="hVT-b6-FRC">
@@ -451,6 +454,9 @@
451 454 <class className="CBFAgendaTableViewController" superclassName="CoreDataTableViewController">
452 455 <source key="sourceIdentifier" type="project" relativePath="./Classes/CBFAgendaTableViewController.h"/>
453 456 </class>
  457 + <class className="CBFImageViewController" superclassName="UIViewController">
  458 + <source key="sourceIdentifier" type="project" relativePath="./Classes/CBFImageViewController.h"/>
  459 + </class>
454 460 <class className="CBFManagedNavViewController" superclassName="UINavigationController">
455 461 <source key="sourceIdentifier" type="project" relativePath="./Classes/CBFManagedNavViewController.h"/>
456 462 </class>
@@ -485,7 +491,7 @@
485 491 <relationship kind="outlet" name="gestureSwipeRight" candidateClass="UISwipeGestureRecognizer"/>
486 492 </relationships>
487 493 </class>
488   - <class className="CBFShowImageViewController" superclassName="UIViewController">
  494 + <class className="CBFShowImageViewController" superclassName="CBFImageViewController">
489 495 <source key="sourceIdentifier" type="project" relativePath="./Classes/CBFShowImageViewController.h"/>
490 496 </class>
491 497 <class className="CBFShowMapViewController" superclassName="UIViewController">

0 comments on commit 971e09d

Please sign in to comment.
Something went wrong with that request. Please try again.