Re: Infinite Scroll View?
Re: Infinite Scroll View?
- Subject: Re: Infinite Scroll View?
- From: Dave <email@hidden>
- Date: Tue, 08 Oct 2013 08:44:02 +0100
On 7 Oct 2013, at 19:54, Kyle Sluder <email@hidden> wrote:
> On Mon, Oct 7, 2013, at 09:21 AM, Dave wrote:
>> Hi,
>>
>> I'd like to be able to Scroll Infinitely in a Scroll, e.g. when the
>> scrolling is past the last item in the Scroll start displaying the first
>> and when scrolling before the first item, starting displaying the last.
>> The items in this case are UIImageViews and they have a fixed height and
>> a variable width and no one image will be wider that the Scroll View
>> itself. Also it needs to work with pagingEnables = NO, e.g. there will be
>> more than one Image visible.
>>
>> I've playing around a bit and found a some sample code that sort of does
>> it but it doesn't handle the wrapping the Images smoothly (is was written
>> to have paging enabled).
>>
>> My plan was/is to detect when the scrolling had hit before the
>> first/after the last and to move the first Subview to the End or the Last
>> one to the beginning, depending on the direction of movement, but at the
>> moment, I can't seem to see a way of detecting these conditions.
>
> It seems fairly straightforward, if a little labor intensive, to figure
> out the width and placement of all your image views, override
> -layoutSubviews to position only the ones that are potentially visible,
> and implement
> -scrollViewWillEndDragging:withVelocity:targetContentOffset: to figure
> out where to end scrolling, based on the current velocity.
>
> --Kyle Sluder
Thanks Kyle,
That's what I was trying to figure out, whether I needed to re-layout the views based on the positions or whether I could just do it by keeping an Array of the image views separately and rotating this as it scroll past the end. I sort of got this working, but of course the Subviews of the Scroll View just grows and grows!
This is what I got at the moment:
// Scroll past last item detected (in the scrollViewDidScroll delegate method)
if (theScrollView.contentSize.width - theScrollView.contentOffset.x <= 1024)
{
myContentInfo = [self.pContentArray objectAtIndex:0];
[self.pContentArray addObject:myContentInfo];
[self.pContentArray removeObjectAtIndex:0];
[self addContentInfo:myContentInfo withEndFlag:YES];
}
Which kind of works, but obviously isn't the way to do it.
Thanks for confirming I needed to use -layoutSubviews, I'm about to start on this track now.
All the Best
Dave
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden