2014-10-06 605 views

回答

0

縱觀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]; 
} 
+0

有沒有辦法讓它像自動滾動,每次像滑動 – 2014-10-06 05:29:14

+0

像一些基於定時器的一個在iOS應用商店 – 2014-10-06 05:31:05

+0

當然,如果你實現了一個定時器,一旦觸發每一秒左右,增加索引並調用scrollToItemAtIndex函數。您可能希望將iCarousel上的wrapEnabled屬性設置爲YES,以便滾動連續包裝。 – 2014-10-06 05:35:28

2

這解決了我的問題 在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++; 
    } 
} 
1

在你ViewDidLoad method

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 

    //configure carousel 
    carousel.type=iCarouselTypeCylinder; 
    carousel.autoscroll=0.4; 
} 
0
- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 

    carousel.type=iCarouselTypeCylinder; 
    carousel.autoscroll=0.8; 
    [carousel reloadData]; 
}