我正在使用Icarousel编写一个Iphone应用程序。我用了两个旋转木马。当我第一次滚动,第二次与第一次,当我滚动第二次,第一滚动与第二次。
我可以正确地做到这一点,但我有一个问题是无限循环。
- (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];
}
}显示为**第二卷**第一卷**第二卷**第一卷.
发布于 2013-05-17 08:15:40
使用Integer变量来跟踪旋转木马被滚动了多少次。在.h文件中添加:
@property (nonatomic) NSUInteger numberofScrolls;在viewDidLoad中这样做:
self.numberofScrolls=0;试试这个:
- (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];
}
}
}让我解释一下它的作用:当视图加载时,我们将numberofScrolls设置为0。当用户停止滚动时,调用carouselDidEndScrollingAnimation ->我们将numberofScrolls增加1,旋转木马2被滚动到相同的位置。旋转木马2使用滚动完成后,carouselDidEndScrollingAnimation将再次被调用。我们再次增加numberofScrolls (现在是2)。但是这一次我们不需要再次滚动另一个视图,self.numberofScrolls%2变成0。
https://stackoverflow.com/questions/16603290
复制相似问题