ImageScrollerViewController.m 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. //
  2. // ImageScrollerViewController.m
  3. // RedAnt ERP Mobile
  4. //
  5. // Created by Ray on 12/18/15.
  6. // Copyright © 2015 United Software Applications, Inc. All rights reserved.
  7. //
  8. #import "ImageScrollerViewController.h"
  9. #import "AppDelegate.h"
  10. #import "RAUtils.h"
  11. @interface ImageScrollerViewController ()
  12. @end
  13. @implementation ImageScrollerViewController
  14. //-(void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
  15. //{
  16. //// UIApplication * app = [UIApplication sharedApplication];
  17. //// AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  18. //// [appDelegate didRotated];
  19. // UIInterfaceOrientation orientation = [[UIApplication sharedApplication]statusBarOrientation];
  20. // if (UIInterfaceOrientationIsLandscape(orientation)|| UIInterfaceOrientationIsPortrait(orientation))
  21. // {
  22. //
  23. // int index = self.imgShowView.curIndex;
  24. // for(UIView* v in self.view.subviews)
  25. // {
  26. // if(v.tag==199)
  27. // [ v removeFromSuperview];
  28. // }
  29. //
  30. // self.imgShowView = [[ImageScrollerView alloc]
  31. // initWithFrame:CGRectMake(self.view.frame.origin.x, self.view.frame.origin.y+42, self.view.frame.size.width, self.view.frame.size.height-84) //self.view.frame
  32. // withSourceData:_data
  33. // withIndex:index];
  34. // self.imgShowView.autoresizingMask = UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth;
  35. //
  36. // self.imgShowView.tag = 199;
  37. // [self.view addSubview:self.imgShowView];
  38. //
  39. // }
  40. //
  41. //
  42. //
  43. //
  44. //}
  45. - (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator {
  46. [super viewWillTransitionToSize:size withTransitionCoordinator:coordinator];
  47. [coordinator animateAlongsideTransition:^(id<UIViewControllerTransitionCoordinatorContext> _Nonnull context) {
  48. // what ever you want to prepare
  49. } completion:^(id<UIViewControllerTransitionCoordinatorContext> _Nonnull context) {
  50. UIInterfaceOrientation orientation =[RAUtils query_orientation:self];// [[UIApplication sharedApplication]statusBarOrientation];
  51. if (UIInterfaceOrientationIsLandscape(orientation)|| UIInterfaceOrientationIsPortrait(orientation))
  52. {
  53. int index = self.imgShowView.curIndex;
  54. for(UIView* v in self.view.subviews)
  55. {
  56. if(v.tag==199)
  57. [ v removeFromSuperview];
  58. }
  59. self.imgShowView = [[ImageScrollerView alloc]
  60. initWithFrame:CGRectMake(self.view.frame.origin.x, self.view.frame.origin.y+42, self.view.frame.size.width, self.view.frame.size.height-84) //self.view.frame
  61. withSourceData:self->_data
  62. withIndex:index];
  63. self.imgShowView.autoresizingMask = UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth;
  64. self.imgShowView.tag = 199;
  65. [self.view addSubview:self.imgShowView];
  66. }
  67. }];
  68. }
  69. - (id)initWithSourceData:(NSMutableArray *)data withIndex:(NSInteger)index{
  70. self = [super init];
  71. if (self) {
  72. self.use_url =false;
  73. self=[self init];
  74. _data = data;
  75. _index = (int)index;
  76. }
  77. return self;
  78. }
  79. - (id)initWithSourceURL:(NSMutableArray *)urls withIndex:(NSInteger)index{
  80. self = [super init];
  81. if (self) {
  82. self=[self init];
  83. // NSMutableArray* data = [[NSMutableArray alloc]init];
  84. // UIImage* qrimg=[QRCodeGenerator qrImageForString:[section_json valueForKey:@"model_name"] imageSize:350];
  85. // if(qrimg!=nil)
  86. // [cell AddPhoto:qrimg];
  87. self.use_url =true;
  88. _data = urls;
  89. _index = (int)index;
  90. }
  91. return self;
  92. }
  93. - (BOOL)prefersStatusBarHidden
  94. {
  95. return YES; //返回NO表示要显示,返回YES将hiden
  96. }
  97. - (void)viewDidLoad {
  98. [super viewDidLoad];
  99. // self.automaticallyAdjustsScrollViewInsets = NO;
  100. self.view.backgroundColor = [UIColor blackColor];
  101. // self.prefersStatusBarHidden = TRUE;
  102. self.btn_close = [[UIButton alloc] initWithFrame:CGRectMake(self.view.frame.size.width-37, 5, 32, 32)];
  103. [self.btn_close setBackgroundImage:[UIImage imageNamed:@"iv_close"] forState:UIControlStateNormal];
  104. [self.btn_close addTarget:self action:@selector(backAction) forControlEvents:UIControlEventTouchUpInside];
  105. // UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction:)];
  106. // [self.view addGestureRecognizer:tap];
  107. self.btn_close.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin;
  108. [self.view addSubview:self.btn_close];
  109. [self creatImgShow];
  110. if (@available(iOS 11, *)) {
  111. self.imgShowView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
  112. }
  113. // else {
  114. //
  115. //
  116. //
  117. // self.automaticallyAdjustsScrollViewInsets = NO;
  118. // }
  119. // Do any additional setup after loading the view.
  120. }
  121. - (void)backAction{
  122. [self.navigationController popViewControllerAnimated:true];
  123. }
  124. - (void)didReceiveMemoryWarning {
  125. [super didReceiveMemoryWarning];
  126. // Dispose of any resources that can be recreated.
  127. }
  128. - (void)creatImgShow{
  129. ImageScrollerView *imgShowView=nil;
  130. if(self.use_url)
  131. {
  132. imgShowView= [[ImageScrollerView alloc]
  133. initWithFrame:CGRectMake(self.view.frame.origin.x, self.view.frame.origin.y+42, self.view.frame.size.width, self.view.frame.size.height-84) //self.view.frame
  134. withSourceURL:_data
  135. withIndex:_index];
  136. }
  137. else
  138. {
  139. imgShowView= [[ImageScrollerView alloc]
  140. initWithFrame:CGRectMake(self.view.frame.origin.x, self.view.frame.origin.y+42, self.view.frame.size.width, self.view.frame.size.height-84) //self.view.frame
  141. withSourceData:_data
  142. withIndex:_index];
  143. }
  144. // 解决谦让
  145. // [imgShowView requireDoubleGestureRecognizer:[[self.view gestureRecognizers] lastObject]];
  146. // UIViewAutoresizingNone = 0,
  147. // UIViewAutoresizingFlexibleLeftMargin = 1 << 0,
  148. // UIViewAutoresizingFlexibleWidth = 1 << 1,
  149. // UIViewAutoresizingFlexibleRightMargin = 1 << 2,
  150. // UIViewAutoresizingFlexibleTopMargin = 1 << 3,
  151. // UIViewAutoresizingFlexibleHeight = 1 << 4,
  152. // UIViewAutoresizingFlexibleBottomMargin = 1 << 5
  153. imgShowView.autoresizingMask = UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth;
  154. self.imgShowView = imgShowView;
  155. self.imgShowView.tag = 199;
  156. [self.view addSubview:imgShowView];
  157. }
  158. //- (void)tapAction:(UITapGestureRecognizer *)tap
  159. //{
  160. //[self.navigationController popViewControllerAnimated:true];
  161. //
  162. //}
  163. /*
  164. #pragma mark - Navigation
  165. // In a storyboard-based application, you will often want to do a little preparation before navigation
  166. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  167. // Get the new view controller using [segue destinationViewController].
  168. // Pass the selected object to the new view controller.
  169. }
  170. */
  171. @end