The basic idea is to set yourself as a UIScrollViewDelegate and apply some modulo arithmetic to the scroll position in order to wrap it around.
Up vote 1 down vote favorite 2 share g+ share fb share tw.
I have this code for a scrollview to showe 3 images: const CGFloat kScrollObjHeight = 150.0; const CGFloat kScrollObjWidth = 320.0; const NSUInteger kNumImages = 3; - (void)layoutScrollImages { UIImageView *view = nil; NSArray *subviews = scrollView1 subviews; // reposition all image subviews in a horizontal serial fashion CGFloat curXLoc = 0; for (view in subviews) { if (view isKindOfClass:UIImageView class && view. Tag > 0) { CGRect frame = view. Frame; frame.
Origin = CGPointMake(curXLoc, 0); view. Frame = frame; curXLoc += (kScrollObjWidth); } } // set the content size so it can be scrollable scrollView1 setContentSize:CGSizeMake((kNumImages * kScrollObjWidth), scrollView1 bounds.size. Height); } - (void)viewDidLoad { self.view.
BackgroundColor = UIColor viewFlipsideBackgroundColor; // 1. Setup the scrollview for multiple images and add it to the view controller // // note: the following can be done in Interface Builder, but we show this in code for clarity scrollView1 setBackgroundColor:UIColor blackColor; scrollView1 setCanCancelContentTouches:NO; scrollView1. IndicatorStyle = UIScrollViewIndicatorStyleWhite; scrollView1.
ClipsToBounds = YES; // default is NO, we want to restrict drawing within our scrollview scrollView1. ScrollEnabled = YES; // pagingEnabled property default is NO, if set the scroller will stop or snap at each photo // if you want free-flowing scroll, don't set this property. ScrollView1.
PagingEnabled = YES; scrollView2. PagingEnabled = YES; scrollView3. PagingEnabled = YES; // load all the images from our bundle and add them to the scroll view NSUInteger i; for (i = 1; I Jpg", i; UIImage *image = UIImage imageNamed:imageName; UIImageView *imageView = UIImageView alloc initWithImage:image; // setup each frame to a default height and width, it will be properly placed when we call "updateScrollList" CGRect rect = imageView.
Frame; rect.size. Height = kScrollObjHeight; rect.size. Width = kScrollObjWidth; imageView.
Frame = rect; imageView. Tag = i; // tag our images for later use when we place them in serial fashion scrollView1 addSubview:imageView; //scrollView2 addSubview:imageView; //scrollView3 addSubview:imageView; imageView release; } self layoutScrollImages; // now place the photos in serial layout within the scrollview } But now I want to do a scrollview that when is in last image show me after the first image of scroll view and the same thing when I have the first image if I go back, it must show the last image; so I want create a paging loop. Ios xcode loops uiscrollview link|improve this question asked Jul 31 '11 at 20:02blackguardian947738 88% accept rate.
The basic idea is to set yourself as a UIScrollViewDelegate and apply some modulo arithmetic to the scroll position in order to wrap it around. There are two basic variations on the idea. Suppose your images are A, B, C, so you currently have them within the scrollview ordered as ABC.
In the more logically pleasing solution — especially if you had lots and lots of images — you watch the scroll position and as soon as it gets to a position where the view is being pushed rightward and C has left the screen, you reorder the images as CAB and shift the current scroll position one spot to the right so that the move is invisible to the user. To put that another way, the scroll position is restrained to an area of two screens, centred on the middle of B (so, you get all of B and half a screen either side). Whenever you wrap it from somewhere on the left to somewhere on the right you shift all your image views one place to the right.
And vice versa. In the slightly easier to implement variation, instead of creating a scroll view with images arranged ABC, arrange then as CABCA. Then apply the same wrap around logic but to a central area of four screens and don't do any view reshuffling.
Make sure you use just setContentOffset: (or the dot notation, as in scrollView. ContentOffset =) as a setter. SetContentOffset:animated: will negate velocity.
Hello and thanks for the answer. I was hoping you could provide a little more detail. What delegate method should I listen to to decide when to alter the order of the images and change the content offset?
In reference to the first solution you offered. – jmurphy Jan 30 at 5:26 1 scrollviewDidScroll: is the most appropriate - it'll give you a shout every time the user changes the contentOffset. – Tommy Jan 30 at 8:43 Thanks.
I'm now listening for scrollViewDidScroll and setting my contentSize to 3 * sizeOfContent. When the user scrolls I'm checking if the content offset is either 0 or 640 (my content is 320). If 0 user scrolled left so re-order contentArray one position left and setContentOffset to 320.
And opposite if offset is 640. I also set bounce = NO so these offsets can only be hit once per swipe. Does that sound like a reasonable approach to you and is that basically what you had in mind?
– jmurphy Jan 30 at 19:56 1 You might have problems if the user is scrolling quickly and don't hit exactly the numbers you want. I was thinking something along the lines of if(contentOffset. X > 480) { shuffle tiles on position to left; contentOffset.
X = fmodf(contentOffset. X, 320.0f);} and if(contentOffset. X X += 320;}.
Just invented here while I type, not tested. – Tommy Jan 30 at 20:06.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.