ImageScrollerViewController.m 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  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. int index = self.imgShowView.curIndex;
  22. for(UIView* v in self.view.subviews)
  23. {
  24. if(v.tag==199)
  25. [ v removeFromSuperview];
  26. }
  27. self.imgShowView = [[ImageScrollerView alloc]
  28. 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
  29. withSourceData:_data
  30. withIndex:index];
  31. self.imgShowView.autoresizingMask = UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth;
  32. self.imgShowView.tag = 199;
  33. [self.view addSubview:self.imgShowView];
  34. }
  35. }
  36. - (id)initWithSourceData:(NSMutableArray *)data withIndex:(NSInteger)index{
  37. self = [super init];
  38. if (self) {
  39. self.use_url =false;
  40. self=[self init];
  41. _data = data;
  42. _index = (int)index;
  43. }
  44. return self;
  45. }
  46. - (id)initWithSourceURL:(NSMutableArray *)urls withIndex:(NSInteger)index{
  47. self = [super init];
  48. if (self) {
  49. self=[self init];
  50. // NSMutableArray* data = [[NSMutableArray alloc]init];
  51. // UIImage* qrimg=[QRCodeGenerator qrImageForString:[section_json valueForKey:@"model_name"] imageSize:350];
  52. // if(qrimg!=nil)
  53. // [cell AddPhoto:qrimg];
  54. self.use_url =true;
  55. _data = urls;
  56. _index = (int)index;
  57. }
  58. return self;
  59. }
  60. - (BOOL)prefersStatusBarHidden
  61. {
  62. return YES; //返回NO表示要显示,返回YES将hiden
  63. }
  64. - (void)viewDidLoad {
  65. [super viewDidLoad];
  66. // self.automaticallyAdjustsScrollViewInsets = NO;
  67. self.view.backgroundColor = [UIColor blackColor];
  68. // self.prefersStatusBarHidden = TRUE;
  69. self.btn_close = [[UIButton alloc] initWithFrame:CGRectMake(self.view.frame.size.width-37, 5, 32, 32)];
  70. [self.btn_close setBackgroundImage:[UIImage imageNamed:@"iv_close"] forState:UIControlStateNormal];
  71. [self.btn_close addTarget:self action:@selector(backAction) forControlEvents:UIControlEventTouchUpInside];
  72. // UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction:)];
  73. // [self.view addGestureRecognizer:tap];
  74. self.btn_close.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin;
  75. [self.view addSubview:self.btn_close];
  76. [self creatImgShow];
  77. if (@available(iOS 11, *)) {
  78. self.imgShowView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
  79. }
  80. else {
  81. self.automaticallyAdjustsScrollViewInsets = NO;
  82. }
  83. // Do any additional setup after loading the view.
  84. }
  85. - (void)backAction{
  86. [self.navigationController popViewControllerAnimated:true];
  87. }
  88. - (void)didReceiveMemoryWarning {
  89. [super didReceiveMemoryWarning];
  90. // Dispose of any resources that can be recreated.
  91. }
  92. - (void)creatImgShow{
  93. ImageScrollerView *imgShowView=nil;
  94. if(self.use_url)
  95. {
  96. imgShowView= [[ImageScrollerView alloc]
  97. 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
  98. withSourceURL:_data
  99. withIndex:_index];
  100. }
  101. else
  102. {
  103. imgShowView= [[ImageScrollerView alloc]
  104. 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
  105. withSourceData:_data
  106. withIndex:_index];
  107. }
  108. // 解决谦让
  109. // [imgShowView requireDoubleGestureRecognizer:[[self.view gestureRecognizers] lastObject]];
  110. // UIViewAutoresizingNone = 0,
  111. // UIViewAutoresizingFlexibleLeftMargin = 1 << 0,
  112. // UIViewAutoresizingFlexibleWidth = 1 << 1,
  113. // UIViewAutoresizingFlexibleRightMargin = 1 << 2,
  114. // UIViewAutoresizingFlexibleTopMargin = 1 << 3,
  115. // UIViewAutoresizingFlexibleHeight = 1 << 4,
  116. // UIViewAutoresizingFlexibleBottomMargin = 1 << 5
  117. imgShowView.autoresizingMask = UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth;
  118. self.imgShowView = imgShowView;
  119. self.imgShowView.tag = 199;
  120. [self.view addSubview:imgShowView];
  121. }
  122. //- (void)tapAction:(UITapGestureRecognizer *)tap
  123. //{
  124. //[self.navigationController popViewControllerAnimated:true];
  125. //
  126. //}
  127. /*
  128. #pragma mark - Navigation
  129. // In a storyboard-based application, you will often want to do a little preparation before navigation
  130. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  131. // Get the new view controller using [segue destinationViewController].
  132. // Pass the selected object to the new view controller.
  133. }
  134. */
  135. @end