Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Same pagination for Two UIScrollview
- -(void)scrollViewDidScroll:(UIScrollView *)sender {
- // Switch the indicator when more than 50% of the previous/next page is visible
- CGFloat pageWidth = self.scrollGalery.frame.size.width;
- currentPage = floor((self.scrollGalery.contentOffset.x - pageWidth / 2) / pageWidth) + 1;
- CGFloat pageWidthBack = self.scrollGaleryBack.frame.size.width;
- currentPageBack = floor((self.scrollGaleryBack.contentOffset.x - pageWidthBack / 2) / pageWidthBack) + 1;
- }
- - (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
- [self updateDisplay];
- }
- - (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView{
- }
- -(void) onRetrieveDisplayObjects:(UIView *)view
- {
- [super onRetrieveDisplayObjects:view];
- self.scrollGalery = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 40, screenWidth, screenHeight-40)];
- self.scrollGalery.contentSize = CGSizeMake(1000, self.scrollGalery.frame.size.height);
- self.scrollGalery.pagingEnabled = YES;
- self.scrollGalery.backgroundColor = [UIColor clearColor];
- self.scrollGalery.showsHorizontalScrollIndicator = NO;
- self.scrollGalery.delegate = self;
- [self.view addSubview:self.scrollGalery];
- self.scrollGaleryBack= [[UIScrollView alloc] initWithFrame:CGRectMake(0, 40, 480, 280)];
- self.scrollGaleryBack.contentSize = CGSizeMake(480, 280);
- self.scrollGaleryBack.pagingEnabled = YES;
- self.scrollGaleryBack.backgroundColor = [UIColor clearColor];
- self.scrollGaleryBack.showsHorizontalScrollIndicator = NO;
- self.scrollGaleryBack.delegate = self;
- [self.view addSubview:self.scrollGaleryBack];
- scrollGalery.hidden = NO;
- scrollGaleryBack.hidden = YES;
- self.forward = [MyLittleUtils newButton:@" "
- andTarget:self.responderRedirector
- andAction:@selector(onForward:) andBackground:@"forward"];
- forward.frame = CGRectMake(screenWidth-50, screenHeight-35, 50, 25);
- [self.view addSubview:self.forward];
- self.backward = [MyLittleUtils newButton:@" "
- andTarget:self.responderRedirector
- andAction:@selector(onBackward:) andBackground:@"backward"];
- backward.frame = CGRectMake(0, screenHeight-35, 50, 25);
- backward.hidden = YES;
- [self.view addSubview:self.backward];
- - (void) onFulfillDisplayObjects
- {
- [super onFulfillDisplayObjects];
- NSArray * listeIllustrations = [self.businessObject getObject];
- float x = 0;
- float z = 0;
- for (Illustration * illustration in listeIllustrations)
- {
- NSString * labelIllustration = [NSString stringWithFormat:@"%@", illustration.label];
- NSString * urlIllustration = [NSString stringWithFormat:@"%@", illustration.url];
- labelU.text = labelIllustration;
- UIImageView * theImage = [[UIImageView alloc] initWithFrame:CGRectMake(x, 20, screenWidth, self.scrollGalery.frame.size.height-20-60)];
- theImage.backgroundColor = [UIColor clearColor];
- //theImage.contentMode = UIViewContentModeScaleToFill;
- theImage.contentMode = UIViewContentModeScaleAspectFit;
- //theImage.contentMode = UIViewContentModeScaleToFill;
- [[SnSImageViewDownloadImageOperation alloc] initAndEnqueueWith:YES
- andTarget:theImage
- andUrl:urlIllustration
- andTemporaryImage:nil];
- [self.scrollGalery addSubview:theImage];
- UITextView * textView = [[UITextView alloc] initWithFrame:CGRectMake(x+40, 400, screenWidth-80, 60)];
- textView.backgroundColor = [UIColor clearColor];
- textView.textAlignment = UITextAlignmentCenter;
- textView.font = FONT_DEFAULT(12);
- textView.text = illustration.copy;
- textView.editable = NO;
- [self.scrollGalery addSubview:textView];
- UIImageView * theImage2 = [[UIImageView alloc] initWithFrame:CGRectMake(z, 0, 480, 280)];
- theImage2.backgroundColor = [UIColor clearColor];
- if ([illustration.orientation isEqualToString:@"1"]) {
- NSString * urlIllustrationb1 = [NSString stringWithFormat:@"%@", illustration.url2];
- [[SnSImageViewDownloadImageOperation alloc] initAndEnqueueWith:YES
- andTarget:theImage2
- andUrl:urlIllustrationb1
- andTemporaryImage:nil];
- }
- if ([illustration.orientation isEqualToString:@"0"]) {
- NSString * urlIllustrationb2 = [NSString stringWithFormat:@"%@", illustration.url];
- [[SnSImageViewDownloadImageOperation alloc] initAndEnqueueWith:YES
- andTarget:theImage2
- andUrl:urlIllustrationb2
- andTemporaryImage:nil];
- }
- [self.scrollGaleryBack addSubview:theImage2];
- x += screenWidth;
- z += 480;
- }
- self.scrollGalery.contentSize = CGSizeMake(x, screenHeight-navigationBarHeight);
- self.scrollGaleryBack.contentSize = CGSizeMake(z, 320-navigationBarHeight);
- - (void) onForward:(id)sender
- {
- CGFloat pageWidth = self.scrollGalery.frame.size.width;
- CGFloat pageWidthBack = self.scrollGaleryBack.frame.size.width;
- currentPage++;
- currentPageBack++;
- [self.scrollGalery setContentOffset:CGPointMake(currentPage*pageWidth, 0) animated:YES];
- [self.scrollGaleryBack setContentOffset:CGPointMake(currentPageBack*pageWidthBack, 0) animated:YES];
- [self updateDisplay];
- }
- - (void) onBackward:(id)sender
- {
- CGFloat pageWidth = self.scrollGalery.frame.size.width;
- CGFloat pageWidthBack = self.scrollGaleryBack.frame.size.width;
- currentPage--;
- currentPageBack--;
- [self.scrollGalery setContentOffset:CGPointMake(currentPage*pageWidth, 0) animated:YES];
- [self.scrollGaleryBack setContentOffset:CGPointMake(currentPageBack*pageWidthBack, 0) animated:YES];
- [self updateDisplay];
- }
Add Comment
Please, Sign In to add comment