ImageScrollerViewController.m 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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 = 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 = 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. // Do any additional setup after loading the view.
  78. }
  79. - (void)backAction{
  80. [self.navigationController popViewControllerAnimated:true];
  81. }
  82. - (void)didReceiveMemoryWarning {
  83. [super didReceiveMemoryWarning];
  84. // Dispose of any resources that can be recreated.
  85. }
  86. - (void)creatImgShow{
  87. ImageScrollerView *imgShowView=nil;
  88. if(self.use_url)
  89. {
  90. imgShowView= [[ImageScrollerView alloc]
  91. 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
  92. withSourceURL:_data
  93. withIndex:_index];
  94. }
  95. else
  96. {
  97. imgShowView= [[ImageScrollerView alloc]
  98. 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
  99. withSourceData:_data
  100. withIndex:_index];
  101. }
  102. // 解决谦让
  103. // [imgShowView requireDoubleGestureRecognizer:[[self.view gestureRecognizers] lastObject]];
  104. // UIViewAutoresizingNone = 0,
  105. // UIViewAutoresizingFlexibleLeftMargin = 1 << 0,
  106. // UIViewAutoresizingFlexibleWidth = 1 << 1,
  107. // UIViewAutoresizingFlexibleRightMargin = 1 << 2,
  108. // UIViewAutoresizingFlexibleTopMargin = 1 << 3,
  109. // UIViewAutoresizingFlexibleHeight = 1 << 4,
  110. // UIViewAutoresizingFlexibleBottomMargin = 1 << 5
  111. imgShowView.autoresizingMask = UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth;
  112. self.imgShowView = imgShowView;
  113. self.imgShowView.tag = 199;
  114. [self.view addSubview:imgShowView];
  115. }
  116. //- (void)tapAction:(UITapGestureRecognizer *)tap
  117. //{
  118. //[self.navigationController popViewControllerAnimated:true];
  119. //
  120. //}
  121. /*
  122. #pragma mark - Navigation
  123. // In a storyboard-based application, you will often want to do a little preparation before navigation
  124. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  125. // Get the new view controller using [segue destinationViewController].
  126. // Pass the selected object to the new view controller.
  127. }
  128. */
  129. @end