Guest User

Untitled

a guest
Aug 21st, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.13 KB | None | 0 0
  1. Same pagination for Two UIScrollview
  2. -(void)scrollViewDidScroll:(UIScrollView *)sender {
  3. // Switch the indicator when more than 50% of the previous/next page is visible
  4. CGFloat pageWidth = self.scrollGalery.frame.size.width;
  5. currentPage = floor((self.scrollGalery.contentOffset.x - pageWidth / 2) / pageWidth) + 1;
  6. CGFloat pageWidthBack = self.scrollGaleryBack.frame.size.width;
  7. currentPageBack = floor((self.scrollGaleryBack.contentOffset.x - pageWidthBack / 2) / pageWidthBack) + 1;
  8. }
  9. - (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
  10. [self updateDisplay];
  11. }
  12. - (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView{
  13. }
  14.  
  15. -(void) onRetrieveDisplayObjects:(UIView *)view
  16. {
  17. [super onRetrieveDisplayObjects:view];
  18.  
  19. self.scrollGalery = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 40, screenWidth, screenHeight-40)];
  20. self.scrollGalery.contentSize = CGSizeMake(1000, self.scrollGalery.frame.size.height);
  21. self.scrollGalery.pagingEnabled = YES;
  22. self.scrollGalery.backgroundColor = [UIColor clearColor];
  23. self.scrollGalery.showsHorizontalScrollIndicator = NO;
  24. self.scrollGalery.delegate = self;
  25. [self.view addSubview:self.scrollGalery];
  26.  
  27. self.scrollGaleryBack= [[UIScrollView alloc] initWithFrame:CGRectMake(0, 40, 480, 280)];
  28. self.scrollGaleryBack.contentSize = CGSizeMake(480, 280);
  29. self.scrollGaleryBack.pagingEnabled = YES;
  30. self.scrollGaleryBack.backgroundColor = [UIColor clearColor];
  31. self.scrollGaleryBack.showsHorizontalScrollIndicator = NO;
  32. self.scrollGaleryBack.delegate = self;
  33. [self.view addSubview:self.scrollGaleryBack];
  34.  
  35. scrollGalery.hidden = NO;
  36. scrollGaleryBack.hidden = YES;
  37.  
  38. self.forward = [MyLittleUtils newButton:@" "
  39. andTarget:self.responderRedirector
  40. andAction:@selector(onForward:) andBackground:@"forward"];
  41. forward.frame = CGRectMake(screenWidth-50, screenHeight-35, 50, 25);
  42. [self.view addSubview:self.forward];
  43.  
  44. self.backward = [MyLittleUtils newButton:@" "
  45. andTarget:self.responderRedirector
  46. andAction:@selector(onBackward:) andBackground:@"backward"];
  47. backward.frame = CGRectMake(0, screenHeight-35, 50, 25);
  48. backward.hidden = YES;
  49. [self.view addSubview:self.backward];
  50.  
  51. - (void) onFulfillDisplayObjects
  52. {
  53. [super onFulfillDisplayObjects];
  54.  
  55. NSArray * listeIllustrations = [self.businessObject getObject];
  56. float x = 0;
  57. float z = 0;
  58. for (Illustration * illustration in listeIllustrations)
  59. {
  60. NSString * labelIllustration = [NSString stringWithFormat:@"%@", illustration.label];
  61. NSString * urlIllustration = [NSString stringWithFormat:@"%@", illustration.url];
  62. labelU.text = labelIllustration;
  63.  
  64. UIImageView * theImage = [[UIImageView alloc] initWithFrame:CGRectMake(x, 20, screenWidth, self.scrollGalery.frame.size.height-20-60)];
  65. theImage.backgroundColor = [UIColor clearColor];
  66. //theImage.contentMode = UIViewContentModeScaleToFill;
  67. theImage.contentMode = UIViewContentModeScaleAspectFit;
  68. //theImage.contentMode = UIViewContentModeScaleToFill;
  69. [[SnSImageViewDownloadImageOperation alloc] initAndEnqueueWith:YES
  70. andTarget:theImage
  71. andUrl:urlIllustration
  72. andTemporaryImage:nil];
  73. [self.scrollGalery addSubview:theImage];
  74.  
  75. UITextView * textView = [[UITextView alloc] initWithFrame:CGRectMake(x+40, 400, screenWidth-80, 60)];
  76. textView.backgroundColor = [UIColor clearColor];
  77. textView.textAlignment = UITextAlignmentCenter;
  78. textView.font = FONT_DEFAULT(12);
  79. textView.text = illustration.copy;
  80. textView.editable = NO;
  81. [self.scrollGalery addSubview:textView];
  82.  
  83. UIImageView * theImage2 = [[UIImageView alloc] initWithFrame:CGRectMake(z, 0, 480, 280)];
  84. theImage2.backgroundColor = [UIColor clearColor];
  85.  
  86. if ([illustration.orientation isEqualToString:@"1"]) {
  87. NSString * urlIllustrationb1 = [NSString stringWithFormat:@"%@", illustration.url2];
  88. [[SnSImageViewDownloadImageOperation alloc] initAndEnqueueWith:YES
  89. andTarget:theImage2
  90. andUrl:urlIllustrationb1
  91. andTemporaryImage:nil];
  92. }
  93. if ([illustration.orientation isEqualToString:@"0"]) {
  94. NSString * urlIllustrationb2 = [NSString stringWithFormat:@"%@", illustration.url];
  95. [[SnSImageViewDownloadImageOperation alloc] initAndEnqueueWith:YES
  96. andTarget:theImage2
  97. andUrl:urlIllustrationb2
  98. andTemporaryImage:nil];
  99. }
  100.  
  101. [self.scrollGaleryBack addSubview:theImage2];
  102.  
  103. x += screenWidth;
  104. z += 480;
  105. }
  106. self.scrollGalery.contentSize = CGSizeMake(x, screenHeight-navigationBarHeight);
  107. self.scrollGaleryBack.contentSize = CGSizeMake(z, 320-navigationBarHeight);
  108.  
  109. - (void) onForward:(id)sender
  110. {
  111. CGFloat pageWidth = self.scrollGalery.frame.size.width;
  112. CGFloat pageWidthBack = self.scrollGaleryBack.frame.size.width;
  113. currentPage++;
  114. currentPageBack++;
  115. [self.scrollGalery setContentOffset:CGPointMake(currentPage*pageWidth, 0) animated:YES];
  116. [self.scrollGaleryBack setContentOffset:CGPointMake(currentPageBack*pageWidthBack, 0) animated:YES];
  117. [self updateDisplay];
  118. }
  119.  
  120. - (void) onBackward:(id)sender
  121. {
  122. CGFloat pageWidth = self.scrollGalery.frame.size.width;
  123. CGFloat pageWidthBack = self.scrollGaleryBack.frame.size.width;
  124. currentPage--;
  125. currentPageBack--;
  126. [self.scrollGalery setContentOffset:CGPointMake(currentPage*pageWidth, 0) animated:YES];
  127. [self.scrollGaleryBack setContentOffset:CGPointMake(currentPageBack*pageWidthBack, 0) animated:YES];
  128. [self updateDisplay];
  129. }
Add Comment
Please, Sign In to add comment