我已經實現了一個基本的滑塊使用iCarousel iOS庫,但我不知道如何使它作爲一個自動滑塊,而不是手動滑動滑動。如何在iOS中實現自動滑動iCarousel?
這裏是我的示例項目的代碼請幫助我
,當我在谷歌搜索我得到這個鏈接,但我不明白什麼
https://github.com/nicklockwood/iCarousel/issues/84
我已經實現了一個基本的滑塊使用iCarousel iOS庫,但我不知道如何使它作爲一個自動滑塊,而不是手動滑動滑動。如何在iOS中實現自動滑動iCarousel?
這裏是我的示例項目的代碼請幫助我
,當我在谷歌搜索我得到這個鏈接,但我不明白什麼
https://github.com/nicklockwood/iCarousel/issues/84
縱觀github上鍊接,我假設你想在查看時自動滾動到一個項目。
您已經定義的函數
- (void)scrollToItemAtIndex:(NSInteger)index animated:(BOOL)animated
然而,這是不是代表iCarousel的一部分,它已被定義爲類的一部分,因此,你只需要調用它。將viewDidAppear放在viewDidAppear中看起來很合適,如果您希望它在您的視圖控制器呈現給用戶時自動滾動到特定索引。只需添加下面的方法即可。
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
// The index of 3 was just chosen as an example
NSInteger chosenIndex = 3;
[self.carousel scrollToItemAtIndex:chosenIndex animated:YES];
}
這解決了我的問題 在ViewDidAppear()我對你的Viewcontroller
添加以下行
-(void)viewDidAppear:(BOOL)animated
{
sliderCount=0;
[super viewDidAppear:animated];
[NSTimer scheduledTimerWithTimeInterval:3.0f target:self selector:@selector(runMethod) userInfo:nil repeats:YES];
}
-(void)runMethod
{
[self.carousel scrollToItemAtIndex:sliderCount animated:YES];
if(sliderCount== 7)
{
sliderCount=0;
}
else
{
sliderCount++;
}
}
在你ViewDidLoad method
。
- (void)viewDidLoad
{
[super viewDidLoad];
//configure carousel
carousel.type=iCarouselTypeCylinder;
carousel.autoscroll=0.4;
}
- (void)viewDidLoad
{
[super viewDidLoad];
carousel.type=iCarouselTypeCylinder;
carousel.autoscroll=0.8;
[carousel reloadData];
}
有沒有辦法讓它像自動滾動,每次像滑動 – 2014-10-06 05:29:14
像一些基於定時器的一個在iOS應用商店 – 2014-10-06 05:31:05
當然,如果你實現了一個定時器,一旦觸發每一秒左右,增加索引並調用scrollToItemAtIndex函數。您可能希望將iCarousel上的wrapEnabled屬性設置爲YES,以便滾動連續包裝。 – 2014-10-06 05:35:28