photosViewController.m 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. //
  2. // photosViewController.m
  3. // sjvodios
  4. //
  5. // Created by on 12-6-2.
  6. // Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
  7. //
  8. #import "photosViewController.h"
  9. #import "JXImageView.h"
  10. #import "JXServer.h"
  11. #import "AppDelegate.h"
  12. #import "JXLabel.h"
  13. #import "JXConnection.h"
  14. #import "UIFactory.h"
  15. @implementation photosViewController
  16. @synthesize photos;
  17. @synthesize page=_page;
  18. +(photosViewController*)showPhotos:(NSArray*)a{
  19. if([a count]<=0)
  20. return nil;
  21. photosViewController* vc = [photosViewController alloc];
  22. vc.photos = [a mutableCopy];
  23. vc = [vc init];
  24. // [g_window addSubview:vc.view];
  25. [g_navigation pushViewController:vc animated:YES];
  26. return vc;
  27. }
  28. - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
  29. {
  30. self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
  31. if (self) {
  32. [UIApplication sharedApplication].statusBarHidden = YES;
  33. _array = [[NSMutableArray alloc]init];
  34. //self.view.frame = g_window.bounds;
  35. sv = [[UIScrollView alloc] initWithFrame:self.view.frame];
  36. sv.pagingEnabled = YES;
  37. sv.scrollEnabled = YES;
  38. sv.delegate = self;
  39. sv.showsVerticalScrollIndicator = NO;
  40. sv.showsHorizontalScrollIndicator = NO;
  41. sv.backgroundColor = [UIColor blackColor];
  42. sv.userInteractionEnabled = YES;
  43. sv.minimumZoomScale = 1;
  44. sv.maximumZoomScale = 1;
  45. sv.tag = 1;
  46. [self.view addSubview:sv];
  47. // [sv release];
  48. _iv = [[JXImageView alloc]initWithFrame:CGRectMake(JX_SCREEN_WIDTH-41,0,41,41)];
  49. _iv.image = [UIImage imageNamed:@"playback_close"];
  50. _iv.didTouch = @selector(actionQuit);
  51. _iv.delegate = self;
  52. [self.view addSubview:_iv];
  53. // [_iv release];
  54. [self showImages];
  55. }
  56. return self;
  57. }
  58. -(void)dealloc{
  59. // NSLog(@"photosViewController.dealloc");
  60. [UIApplication sharedApplication].statusBarHidden = NO;
  61. [_array removeAllObjects];
  62. // [_array release];
  63. self.photos = nil;
  64. // [super dealloc];
  65. }
  66. - (void)didReceiveMemoryWarning
  67. {
  68. [super didReceiveMemoryWarning];
  69. }
  70. -(void)viewDidAppear:(BOOL)animated{
  71. }
  72. -(void)showImages{
  73. _photoCount = (int)[photos count];
  74. if(_photoCount<=0)
  75. return;
  76. sv.contentSize = CGSizeMake(sv.frame.size.width*_photoCount, sv.frame.size.height);
  77. for(int i=0;i<_photoCount;i++){
  78. UIScrollView* vi = [[UIScrollView alloc] initWithFrame:CGRectMake(i*sv.frame.size.width,0, sv.frame.size.width,sv.frame.size.height)];
  79. vi.pagingEnabled = NO;
  80. vi.scrollEnabled = YES;
  81. vi.delegate = self;
  82. vi.showsVerticalScrollIndicator = NO;
  83. vi.showsHorizontalScrollIndicator = NO;
  84. vi.backgroundColor = [UIColor blackColor];
  85. vi.userInteractionEnabled = YES;
  86. vi.minimumZoomScale = 1;
  87. vi.maximumZoomScale = 5;
  88. //UIView* vi = [[UIView alloc]initWithFrame:CGRectMake(i*sv.frame.size.width,0, sv.frame.size.width,sv.frame.size.height)];
  89. [sv addSubview:vi];
  90. // [vi release];
  91. JXLabel* lb;
  92. lb = [[JXLabel alloc]initWithFrame:CGRectMake(0, sv.frame.size.height*0.45, sv.frame.size.width, 20)];
  93. lb.textColor = [UIColor whiteColor];
  94. lb.backgroundColor = [UIColor clearColor];
  95. lb.font = g_factory.font13;
  96. lb.textAlignment = NSTextAlignmentCenter;
  97. lb.text = [NSString stringWithFormat:@"%@%d%@..",Localized(@"photosViewController_Reading1"),i+1,Localized(@"photosViewController_Reading2")];
  98. [vi addSubview:lb];
  99. // [lb release];
  100. JXImageView* iv = [[JXImageView alloc]initWithFrame:CGRectMake(0, 0, sv.frame.size.width, sv.frame.size.height)];
  101. iv.userInteractionEnabled = YES;
  102. iv.didTouch = @selector(actionImage);
  103. iv.delegate = self;
  104. iv.changeAlpha = NO;
  105. [vi addSubview:iv];
  106. // [iv release];
  107. [_array addObject:iv];
  108. NSString* url = [(NSDictionary *)[photos objectAtIndex:i] objectForKey:@"oUrl"];
  109. [g_server getImage:url imageView:iv];
  110. }
  111. }
  112. #pragma mark - View lifecycle
  113. - (void)viewDidUnload
  114. {
  115. [super viewDidUnload];
  116. }
  117. - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
  118. {
  119. // Return YES for supported orientations
  120. return (interfaceOrientation == UIInterfaceOrientationPortrait);
  121. }
  122. - (void)setPage
  123. {
  124. sv.contentOffset = CGPointMake(JX_SCREEN_WIDTH*_page, 0.0f);
  125. NSString* url = [(NSDictionary *)[photos objectAtIndex:_page] objectForKey:@"oUrl"];
  126. [g_server getImage:url imageView:[_array objectAtIndex:_page]];
  127. }
  128. - (void)setPage:(int)value{
  129. _page = value;
  130. if(_page<0)
  131. _page=0;
  132. if(_page >= _photoCount)
  133. _page = 0;
  134. [self setPage];
  135. }
  136. -(void)actionLast{
  137. _page--;
  138. if(_page<0)
  139. _page=0;
  140. [self setPage];
  141. }
  142. -(void)actionNext{
  143. _page++;
  144. if(_page >= _photoCount)
  145. _page = 0;
  146. [self setPage];
  147. }
  148. -(void)actionQuit{
  149. [UIFactory onGotoBack:self];
  150. }
  151. -(void)actionImage{
  152. _iv.hidden = !_iv.hidden;
  153. }
  154. - (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
  155. if(scrollView.tag != 1)
  156. return;
  157. int index = scrollView.contentOffset.x/JX_SCREEN_WIDTH;
  158. int mod = fmod(scrollView.contentOffset.x,JX_SCREEN_WIDTH);
  159. if( mod >= 160)
  160. index++;
  161. // NSLog(@"%f,%f,%f",scrollView.contentOffset.x,index,mod);
  162. _page = index;
  163. [self setPage];
  164. [self doReadNext];
  165. }
  166. - (void)scrollViewDidScroll:(UIScrollView *)scrollView{
  167. [self doReadNext];
  168. }
  169. -(void) doReadNext{
  170. if(_page<_photoCount-1){
  171. NSString* url = [(NSDictionary *)[photos objectAtIndex:_page+1] objectForKey:@"oUrl"];
  172. [g_server getImage:url imageView:[_array objectAtIndex:_page+1]];
  173. }
  174. }
  175. - (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView{
  176. if(scrollView.tag == 1)
  177. return nil;
  178. return [_array objectAtIndex:_page];
  179. }
  180. @end