Skip to content

Commit 159363b

Browse files
committedOct 1, 2010
Update EasyGallery
1 parent 933a847 commit 159363b

File tree

10 files changed

+177
-105
lines changed

10 files changed

+177
-105
lines changed
 

‎CirculationScroll/Classes/CirculationScrollAppDelegate.m

+3-4
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,12 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
2626
[window addSubview:viewController.view];
2727
[window makeKeyAndVisible];
2828

29-
/*
3029
// 1 image case
3130
viewController.imageList = [NSArray arrayWithObjects:
3231
[UIImage imageNamed:@"simg1.jpg"],nil];
33-
*/
3432

35-
viewController.imageList = [NSArray arrayWithObjects:
33+
/*
34+
viewController.imageList = [NSArray arrayWithObjects:
3635
[UIImage imageNamed:@"simg1.jpg"],
3736
[UIImage imageNamed:@"simg2.jpg"],
3837
[UIImage imageNamed:@"simg3.jpg"],
@@ -43,7 +42,7 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
4342
[UIImage imageNamed:@"simg8.jpg"],
4443
[UIImage imageNamed:@"simg9.jpg"],
4544
nil];
46-
45+
*/
4746
return YES;
4847
}
4948

‎CirculationScroll/Classes/CirculationScrollViewController.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
UIScrollView* scrollView_;
1414
NSArray* viewList_;
15-
15+
1616
NSArray* imageList_;
1717

1818
NSInteger leftImageIndex_; // index of imageList

‎CirculationScroll/Classes/CirculationScrollViewController.m

+12-10
Original file line numberDiff line numberDiff line change
@@ -119,18 +119,20 @@ - (void)viewDidLoad {
119119
}
120120
self.viewList = array;
121121

122-
[self stopAutoScroll];
122+
123+
if (circulated_) {
124+
[self stopAutoScroll];
123125

124-
if ([self.timer isValid]) {
125-
[self.timer invalidate];
126+
if ([self.timer isValid]) {
127+
[self.timer invalidate];
128+
}
129+
self.timer = [NSTimer scheduledTimerWithTimeInterval:SCROLL_INTERVAL
130+
target:self
131+
selector:@selector(timerDidFire:)
132+
userInfo:nil
133+
repeats:YES];
134+
[self restartAutoScrollAfterDelay];
126135
}
127-
self.timer = [NSTimer scheduledTimerWithTimeInterval:SCROLL_INTERVAL
128-
target:self
129-
selector:@selector(timerDidFire:)
130-
userInfo:nil
131-
repeats:YES];
132-
[self restartAutoScrollAfterDelay];
133-
134136
}
135137

136138
- (void)didReceiveMemoryWarning {

‎EasyGallery/Classes/EasyGalleryViewController.h

+6-8
Original file line numberDiff line numberDiff line change
@@ -11,25 +11,23 @@
1111
@interface EasyGalleryViewController : UIViewController {
1212

1313
NSMutableArray* imageFiles_;
14+
NSInteger currentImageIndex_;
1415

1516
UIScrollView* scrollView_;
17+
NSInteger contentOffsetIndex_;
1618

17-
UIScrollView* previousScrollView_;
18-
UIScrollView* currentScrollView_;
19-
UIScrollView* nextScrollView_;
19+
NSMutableArray* imageScrollViews_;
2020

21-
NSInteger currentIndex_;
2221
}
2322

2423
@property (nonatomic, retain) IBOutlet NSMutableArray* imageFiles;
24+
@property (nonatomic, assign) NSInteger currentImageIndex;
2525

2626
@property (nonatomic, retain) IBOutlet UIScrollView* scrollView;
27+
@property (nonatomic, assign) NSInteger contentOffsetIndex;
2728

28-
@property (nonatomic, retain) UIScrollView* previousScrollView;
29-
@property (nonatomic, retain) UIScrollView* currentScrollView;
30-
@property (nonatomic, retain) UIScrollView* nextScrollView;
29+
@property (nonatomic, retain) NSMutableArray* imageScrollViews;
3130

32-
@property (nonatomic, assign) NSInteger currentIndex;
3331

3432
@end
3533

‎EasyGallery/Classes/EasyGalleryViewController.m

+88-80
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,22 @@
99
#import "EasyGalleryViewController.h"
1010
#import "CustomImageView.h"
1111

12+
enum {
13+
kIndexOfPreviousScrollView = 0,
14+
kIndexOfCurrentScrollView,
15+
kIndexOfNextScrollView,
16+
kMaxOfScrollView
17+
};
18+
1219
@implementation EasyGalleryViewController
1320

1421
@synthesize imageFiles = imageFiles_;
22+
@synthesize currentImageIndex = currentImageIndex_;
1523

1624
@synthesize scrollView = scrollView_;
25+
@synthesize contentOffsetIndex = contentOffsetIndex_;
1726

18-
@synthesize previousScrollView = previousScrollView_;
19-
@synthesize currentScrollView = currentScrollView_;
20-
@synthesize nextScrollView = nextScrollView_;
21-
22-
@synthesize currentIndex = currentIndex_;
23-
27+
@synthesize imageScrollViews = imageScrollViews_;
2428

2529
#pragma mark -
2630
#pragma mark Controle scroll views
@@ -41,24 +45,20 @@ - (void)setImageAtIndex:(NSInteger)index toScrollView:(UIScrollView*)scrollView
4145
}
4246

4347

44-
- (void)scrollToIndex:(NSInteger)index animated:(BOOL)animated
48+
- (void)layoutScrollViews
4549
{
46-
CGPoint contentOffset =
47-
CGPointMake(index * self.scrollView.frame.size.width, 0);
48-
[self.scrollView setContentOffset:contentOffset animated:animated];
50+
CGSize newSize = self.view.bounds.size;
4951

50-
}
51-
52-
- (void)adjustViews
53-
{
54-
CGSize contentSize = CGSizeMake(
55-
self.currentScrollView.frame.size.width * [self.imageFiles count],
56-
self.currentScrollView.frame.size.height);
57-
self.scrollView.contentSize = contentSize;
52+
CGFloat x = (self.contentOffsetIndex-1) * newSize.width;
53+
for (UIScrollView* scrollView in self.imageScrollViews) {
54+
scrollView.frame = CGRectMake(x, 0, newSize.width, newSize.height);
55+
scrollView.contentSize = newSize;
56+
x += newSize.width;
57+
}
5858

59-
[self setImageAtIndex:self.currentIndex-1 toScrollView:self.previousScrollView];
60-
[self setImageAtIndex:self.currentIndex toScrollView:self.currentScrollView];
61-
[self setImageAtIndex:self.currentIndex+1 toScrollView:self.nextScrollView];
59+
self.scrollView.contentSize = CGSizeMake(
60+
[self.imageFiles count]*newSize.width, newSize.height);
61+
self.scrollView.contentOffset = CGPointMake(self.contentOffsetIndex*newSize.width, 0);
6262
}
6363

6464

@@ -68,33 +68,32 @@ - (void)adjustViews
6868
- (void)viewDidLoad {
6969
[super viewDidLoad];
7070

71-
// setup scroll views
71+
// setup internal scroll views
7272
CGRect imageScrollViewFrame = CGRectZero;
73-
imageScrollViewFrame.size = self.scrollView.frame.size;
74-
imageScrollViewFrame.origin.x = (self.currentIndex-1) * imageScrollViewFrame.size.width;
73+
imageScrollViewFrame.size = self.scrollView.bounds.size;
74+
imageScrollViewFrame.origin.x = (self.contentOffsetIndex-1) * imageScrollViewFrame.size.width;
75+
76+
self.imageScrollViews = [NSMutableArray array];
7577

7678
CGRect imageViewFrame = CGRectZero;
77-
imageViewFrame.size = self.scrollView.frame.size;
79+
imageViewFrame.size = self.scrollView.bounds.size;
7880

79-
for (int i=0; i < 3; i++) {
81+
for (int i=0; i < kMaxOfScrollView; i++) {
8082

8183
// image view
8284
CustomImageView* imageView =
8385
[[CustomImageView alloc] initWithFrame:imageViewFrame];
84-
/*
8586
imageView.autoresizingMask =
8687
UIViewAutoresizingFlexibleLeftMargin |
8788
UIViewAutoresizingFlexibleWidth |
8889
UIViewAutoresizingFlexibleRightMargin |
8990
UIViewAutoresizingFlexibleTopMargin |
9091
UIViewAutoresizingFlexibleHeight |
9192
UIViewAutoresizingFlexibleBottomMargin;
92-
*/
93-
// imageView.delegate = self;
9493

9594
// scroll view
9695
UIScrollView* imageScrollView =
97-
[[UIScrollView alloc] initWithFrame:imageScrollViewFrame];
96+
[[UIScrollView alloc] initWithFrame:imageScrollViewFrame];
9897
imageScrollView.minimumZoomScale = 1.0;
9998
imageScrollView.maximumZoomScale = 5.0;
10099
imageScrollView.showsHorizontalScrollIndicator = NO;
@@ -105,44 +104,41 @@ - (void)viewDidLoad {
105104
[imageScrollView addSubview:imageView];
106105
[self.scrollView addSubview:imageScrollView];
107106

108-
// assign to iVars
109-
switch (i) {
110-
case 0:
111-
self.previousScrollView = imageScrollView;
112-
break;
113-
case 1:
114-
self.currentScrollView = imageScrollView;
115-
break;
116-
case 2:
117-
self.nextScrollView = imageScrollView;
118-
break;
119-
}
107+
// store scrollViews
108+
[self.imageScrollViews addObject:imageScrollView];
120109

121110
// release all
122111
[imageView release];
123112
[imageScrollView release];
124-
113+
114+
// setup initial image
115+
[self setImageAtIndex:i-1 toScrollView:imageScrollView];
116+
125117
// next image
126118
imageScrollViewFrame.origin.x += imageScrollViewFrame.size.width;
127119
}
128120

121+
// setup base scroll view
129122
self.scrollView.pagingEnabled = YES;
130123
self.scrollView.showsHorizontalScrollIndicator = NO;
131124
self.scrollView.showsVerticalScrollIndicator = NO;
132125
self.scrollView.scrollsToTop = NO;
133-
134-
[self adjustViews];
135-
[self scrollToIndex:self.currentIndex animated:NO];
126+
127+
// final init
128+
[self layoutScrollViews];
136129
}
137130

138131

139-
/*
140-
// Override to allow orientations other than the default portrait orientation.
141132
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
142-
// Return YES for supported orientations
143-
return (interfaceOrientation == UIInterfaceOrientationPortrait);
133+
return YES;
134+
}
135+
136+
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation duration:(NSTimeInterval)duration
137+
{
138+
[self layoutScrollViews];
144139
}
145-
*/
140+
141+
146142

147143
- (void)didReceiveMemoryWarning {
148144
// Releases the view if it doesn't have a superview.
@@ -155,11 +151,7 @@ - (void)viewDidUnload {
155151
self.imageFiles = nil;
156152

157153
self.scrollView = nil;
158-
159-
self.previousScrollView = nil;
160-
self.currentScrollView = nil;
161-
self.nextScrollView = nil;
162-
154+
self.imageScrollViews = nil;
163155
}
164156

165157
- (void)dealloc {
@@ -172,30 +164,42 @@ - (void)dealloc {
172164

173165
-(void)setupPreviousImage
174166
{
175-
UIScrollView* tmpView = self.currentScrollView;
176-
177-
self.currentScrollView = self.previousScrollView;
178-
self.previousScrollView = self.nextScrollView;
179-
self.nextScrollView = tmpView;
180-
181-
CGRect frame = self.currentScrollView.frame;
167+
UIScrollView* previousScrollView =
168+
[self.imageScrollViews objectAtIndex:kIndexOfPreviousScrollView];
169+
UIScrollView* currentScrollView =
170+
[self.imageScrollViews objectAtIndex:kIndexOfCurrentScrollView];
171+
UIScrollView* nextScrollView =
172+
[self.imageScrollViews objectAtIndex:kIndexOfNextScrollView];
173+
174+
[self.imageScrollViews removeAllObjects];
175+
[self.imageScrollViews addObject:nextScrollView];
176+
[self.imageScrollViews addObject:previousScrollView];
177+
[self.imageScrollViews addObject:currentScrollView];
178+
179+
CGRect frame = previousScrollView.frame;
182180
frame.origin.x -= frame.size.width;
183-
self.previousScrollView.frame = frame;
184-
[self setImageAtIndex:self.currentIndex-1 toScrollView:self.previousScrollView];
181+
nextScrollView.frame = frame;
182+
[self setImageAtIndex:self.currentImageIndex-1 toScrollView:nextScrollView];
185183
}
186184

187185
-(void)setupNextImage
188186
{
189-
UIScrollView* tmpView = self.currentScrollView;
190-
191-
self.currentScrollView = self.nextScrollView;
192-
self.nextScrollView = self.previousScrollView;
193-
self.previousScrollView = tmpView;
194-
195-
CGRect frame = self.currentScrollView.frame;
187+
UIScrollView* previousScrollView =
188+
[self.imageScrollViews objectAtIndex:kIndexOfPreviousScrollView];
189+
UIScrollView* currentScrollView =
190+
[self.imageScrollViews objectAtIndex:kIndexOfCurrentScrollView];
191+
UIScrollView* nextScrollView =
192+
[self.imageScrollViews objectAtIndex:kIndexOfNextScrollView];
193+
194+
[self.imageScrollViews removeAllObjects];
195+
[self.imageScrollViews addObject:currentScrollView];
196+
[self.imageScrollViews addObject:nextScrollView];
197+
[self.imageScrollViews addObject:previousScrollView];
198+
199+
CGRect frame = nextScrollView.frame;
196200
frame.origin.x += frame.size.width;
197-
self.nextScrollView.frame = frame;
198-
[self setImageAtIndex:self.currentIndex+1 toScrollView:self.nextScrollView];
201+
previousScrollView.frame = frame;
202+
[self setImageAtIndex:self.currentImageIndex+1 toScrollView:previousScrollView];
199203
}
200204

201205

@@ -204,22 +208,26 @@ -(void)setupNextImage
204208
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
205209
{
206210
CGFloat position = scrollView.contentOffset.x / scrollView.bounds.size.width;
207-
CGFloat delta = position - (CGFloat)self.currentIndex;
211+
CGFloat delta = position - (CGFloat)self.currentImageIndex;
208212

209213
if (fabs(delta) >= 1.0f) {
210-
self.currentScrollView.zoomScale = 1.0;
211-
self.currentScrollView.contentOffset = CGPointZero;
214+
UIScrollView* currentScrollView =
215+
[self.imageScrollViews objectAtIndex:kIndexOfCurrentScrollView];
216+
currentScrollView.zoomScale = 1.0;
217+
currentScrollView.contentOffset = CGPointZero;
212218

213-
// NSLog(@"%f (%d=>%d)", delta, self.currentIndex, index);
219+
// NSLog(@"%f (%d=>%d)", delta, self.currentImageIndex, index);
214220

215221
if (delta > 0) {
216222
// the current page moved to right
217-
self.currentIndex = self.currentIndex+1; // no check (no over case)
223+
self.currentImageIndex = self.currentImageIndex+1;
224+
self.contentOffsetIndex = self.contentOffsetIndex+1;
218225
[self setupNextImage];
219226

220227
} else {
221228
// the current page moved to left
222-
self.currentIndex = self.currentIndex-1; // no check (no over case)
229+
self.currentImageIndex = self.currentImageIndex-1;
230+
self.contentOffsetIndex = self.contentOffsetIndex-1;
223231
[self setupPreviousImage];
224232
}
225233

‎EasyGallery/EasyGallery.xcodeproj/project.pbxproj

+1
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,7 @@
229229
GCC_PRECOMPILE_PREFIX_HEADER = YES;
230230
GCC_PREFIX_HEADER = EasyGallery_Prefix.pch;
231231
INFOPLIST_FILE = "EasyGallery-Info.plist";
232+
IPHONEOS_DEPLOYMENT_TARGET = 4.0;
232233
PRODUCT_NAME = EasyGallery;
233234
};
234235
name = Debug;

‎NetworkReachable/Classes/NetworkReachability.m

+3-2
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ + (NetworkReachability*)networkReachabilityWithHostname:(NSString*)hostname
3232

3333
- (void) dealloc
3434
{
35-
CFRetain(reachability_);
35+
CFRelease(reachability_);
3636
[super dealloc];
3737
}
3838

@@ -52,7 +52,8 @@ - (NSString*)getWiFiIPAddress
5252
NSString *name =
5353
[NSString stringWithUTF8String:cursor->ifa_name];
5454

55-
if ([name isEqualToString:@"en1"]) { // found the WiFi adapter
55+
if ([name isEqualToString:@"en0"] ||
56+
[name isEqualToString:@"en1"]) { // found the WiFi adapter
5657
return [NSString stringWithUTF8String:
5758
inet_ntoa(((struct sockaddr_in *)cursor->ifa_addr)->sin_addr)];
5859
}

‎NetworkReachable/NetworkReachable.xcodeproj/project.pbxproj

+7
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,14 @@
143143
isa = PBXProject;
144144
buildConfigurationList = C01FCF4E08A954540054247B /* Build configuration list for PBXProject "NetworkReachable" */;
145145
compatibilityVersion = "Xcode 3.1";
146+
developmentRegion = English;
146147
hasScannedForEncodings = 1;
148+
knownRegions = (
149+
English,
150+
Japanese,
151+
French,
152+
German,
153+
);
147154
mainGroup = 29B97314FDCFA39411CA2CEA /* CustomTemplate */;
148155
projectDirPath = "";
149156
projectRoot = "";

‎SearchSample/Classes/CustomCell.h

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
//
2+
// CustomCell.h
3+
// SearchSample
4+
//
5+
// Created by Hiroshi Hashiguchi on 10/08/02.
6+
// Copyright 2010 . All rights reserved.
7+
//
8+
9+
#import <UIKit/UIKit.h>
10+
11+
12+
@interface CustomCell : UITableViewCell {
13+
14+
}
15+
16+
@end

‎SearchSample/Classes/CustomCell.m

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
//
2+
// CustomCell.m
3+
// SearchSample
4+
//
5+
// Created by Hiroshi Hashiguchi on 10/08/02.
6+
// Copyright 2010 . All rights reserved.
7+
//
8+
9+
#import "CustomCell.h"
10+
11+
12+
@implementation CustomCell
13+
14+
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
15+
if ((self = [super initWithStyle:style reuseIdentifier:reuseIdentifier])) {
16+
// Initialization code
17+
}
18+
return self;
19+
}
20+
21+
22+
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
23+
24+
[super setSelected:selected animated:animated];
25+
26+
// Configure the view for the selected state
27+
}
28+
29+
30+
- (void)setEditing:(BOOL)editing animated:(BOOL)animated
31+
{
32+
NSLog(@"editing: %d", editing);
33+
}
34+
35+
- (void)dealloc {
36+
[super dealloc];
37+
}
38+
39+
40+
@end

0 commit comments

Comments
 (0)
Please sign in to comment.