Reputation: 631
I'm writting an Iphone application using with Icarousel. I used 2 carousel. When i scroll first, second scroll with first one and when i scroll second, first scroll with the second one.
I can do this correctly but I have a problem that is infinite loop.
- (void)carouselDidEndScrollingAnimation:(iCarousel *)Carousel
{
if (Carousel == carouselSecond)
{
NSLog(@"***Second Scroll");
[carouselFirst scrollToItemAtIndex:carouselSecond.currentItemIndex duration:2];
}
else if(Carousel == carouselFirst)
{
NSLog(@"***First Scroll");
[carouselSecond scrollToItemAtIndex:carouselFirst.currentItemIndex duration:2];
}
}
Display is **Second Scroll **First Scroll **Second Scroll **First Scroll **Second Scroll **First Scroll **Second Scroll **First Scroll ......
Upvotes: 1
Views: 1271
Reputation: 2295
Use an Integer variable to keep track of how many times the carousel has been scrolled. In your .h file add:
@property (nonatomic) NSUInteger numberofScrolls;
in viewDidLoad
do this:
self.numberofScrolls=0;
and try this:
- (void)carouselDidEndScrollingAnimation:(iCarousel *)Carousel
{
self.numberofScrolls++;
if(self.numberofScrolls%2!=0){
if (Carousel == carouselSecond)
{
NSLog(@"***Second Scroll");
[carouselFirst scrollToItemAtIndex:carouselSecond.currentItemIndex duration:2];
}
else if(Carousel == carouselFirst)
{
NSLog(@"***First Scroll");
[carouselSecond scrollToItemAtIndex:carouselFirst.currentItemIndex duration:2];
}
}
}
Let me explain what it does:
When the view loads, we set numberofScrolls
to 0.
When user stops scrolling, the carouselDidEndScrollingAnimation
gets called --> we increase numberofScrolls
by 1 and carousel 2 gets scrolled to the same position. After carousel 2 is done with scrolling, carouselDidEndScrollingAnimation
gets called again. We increase numberofScrolls
once again (it is now 2). But this time we don't need to scroll the other view again and self.numberofScrolls%2
becomes 0.
Upvotes: 2