ImageScrollerViewController.m 7.2 KB

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