Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Try this One. This Code is Working Properly for me on iOS 4.3</p> <p>RootViewController.h</p> <pre><code>@class ViewControllerForDuplicateEndCaps; @interface RootViewController : UIViewController { ViewControllerForDuplicateEndCaps *viewControllerForDuplicateEndCaps; } @property (nonatomic, retain) ViewControllerForDuplicateEndCaps *viewControllerForDuplicateEndCaps; - (IBAction)loadScrollViewWithDuplicateEndCaps:(id)sender; @end </code></pre> <p>RootViewController.m</p> <pre><code>#import "RootViewController.h" #import "ViewControllerForDuplicateEndCaps.h" #import "InfiniteScrollViewAppDelegate.h" @implementation RootViewController @synthesize viewControllerForDuplicateEndCaps; - (IBAction)loadScrollViewWithDuplicateEndCaps:(id)sender { InfiniteScrollViewAppDelegate *delegate = (InfiniteScrollViewAppDelegate*)[[UIApplication sharedApplication] delegate]; if(self.viewControllerForDuplicateEndCaps == nil) { ViewControllerForDuplicateEndCaps *temp = [[ViewControllerForDuplicateEndCaps alloc] initWithNibName:@"ViewControllerForDuplicateEndCaps" bundle:nil]; self.viewControllerForDuplicateEndCaps = temp; [temp release]; } UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithTitle:@"Back" style:UIBarButtonItemStyleBordered target:nil action:nil]; self.navigationItem.backBarButtonItem = backButton; [backButton release]; [delegate.navigationController pushViewController:self.viewControllerForDuplicateEndCaps animated:YES]; } - (void)dealloc { [scrollView release]; [super dealloc]; } @end </code></pre> <p>ViewControllerForDuplicateEndCaps.h</p> <pre><code>#import &lt;UIKit/UIKit.h&gt; @interface ViewControllerForDuplicateEndCaps : UIViewController &lt;UIScrollViewDelegate&gt; { IBOutlet UIScrollView *scrollView; } @property (nonatomic, retain) UIScrollView *scrollView; - (void)addImageWithName:(NSString*)imageString atPosition:(int)position; @end </code></pre> <p>ViewControllerForDuplicateEndCaps.m</p> <pre><code>#import "ViewControllerForDuplicateEndCaps.h" @implementation ViewControllerForDuplicateEndCaps @synthesize scrollView; - (void)viewDidLoad { [super viewDidLoad]; // add the last image (image4) into the first position [self addImageWithName:@"image4.jpg" atPosition:0]; // add all of the images to the scroll view for (int i = 1; i &lt; 5; i++) { [self addImageWithName:[NSString stringWithFormat:@"image%i.jpg",i] atPosition:i]; } // add the first image (image1) into the last position [self addImageWithName:@"image1.jpg" atPosition:5]; scrollView.contentSize = CGSizeMake(1920, 416); [scrollView scrollRectToVisible:CGRectMake(320,0,320,416) animated:NO]; } - (void)addImageWithName:(NSString*)imageString atPosition:(int)position { // add image to scroll view UIImage *image = [UIImage imageNamed:imageString]; UIImageView *imageView = [[UIImageView alloc] initWithImage:image]; imageView.frame = CGRectMake(position*320, 0, 320, 416); [scrollView addSubview:imageView]; [imageView release]; } - (void)scrollViewDidEndDecelerating:(UIScrollView *)sender { NSLog(@"%f",scrollView.contentOffset.x); // The key is repositioning without animation if (scrollView.contentOffset.x == 0) { // user is scrolling to the left from image 1 to image 4 // reposition offset to show image 4 that is on the right in the scroll view [scrollView scrollRectToVisible:CGRectMake(1280,0,320,416) animated:NO]; } else if (scrollView.contentOffset.x == 1600) { // user is scrolling to the right from image 4 to image 1 // reposition offset to show image 1 that is on the left in the scroll view [scrollView scrollRectToVisible:CGRectMake(320,0,320,416) animated:NO]; } } - (void)dealloc { [scrollView release]; [super dealloc]; } @end </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload