我正在與iCarousel - https://github.com/nicklockwood/iCarousel。不同的寬度爲不同的項目 - 在iCarousel
雖然我需要更改不同項目的寬度,但意味着要爲不同的項目設置不同的寬度。
不確定如何進行更改,如果您對此有任何經驗,請幫助。
另一個問題是如何使它滾動時只滾動1項目。 - 表示只滾動到下一個項目,目前它會繼續滾動到下一個項目的下一個...
任何幫助,高度讚賞。
我正在與iCarousel - https://github.com/nicklockwood/iCarousel。不同的寬度爲不同的項目 - 在iCarousel
雖然我需要更改不同項目的寬度,但意味着要爲不同的項目設置不同的寬度。
不確定如何進行更改,如果您對此有任何經驗,請幫助。
另一個問題是如何使它滾動時只滾動1項目。 - 表示只滾動到下一個項目,目前它會繼續滾動到下一個項目的下一個...
任何幫助,高度讚賞。
因爲當滾動你必須添加gestureRecognizer &禁用轉盤的滾動只滾動1項
_myCarousel = [[iCarousel alloc] initWithFrame:CGRectMake(0,0, 310, 100)];
_myCarousel.type = iCarouselTypeCoverFlow2;
_myCarousel.scrollEnabled = NO;
UISwipeGestureRecognizer * swipeleft = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeleft:)];
swipeleft.direction = UISwipeGestureRecognizerDirectionLeft;
[_myCarousel addGestureRecognizer:swipeleft];
UISwipeGestureRecognizer * swiperight = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swiperight:)];
swiperight.direction=UISwipeGestureRecognizerDirectionRight;
[_myCarousel addGestureRecognizer:swiperight];
_myCarousel.dataSource = self;
_myCarousel.delegate = self;
[myView addSubview:_myCarousel];
swipeleft: & swiperight:將作爲
-(void)swipeleft:(UISwipeGestureRecognizer*)gestureRecognizer
{
[_myCarousel scrollByNumberOfItems:1 duration:0.25];
}
-(void)swiperight:(UISwipeGestureRecognizer*)gestureRecognizer
{
[_myCarousel scrollByNumberOfItems:-1 duration:0.25];
}
工作我如預期的那樣。 希望這會幫助你..
問題1:
在iCarousel itemWidth財產是隻讀的,你應該使用轉盤:viewForItemAtIndex:reusingView爲了這個目的:
@property (nonatomic, readonly) CGFloat itemWidth;
項目在傳送帶上的顯示寬度(只讀)。這是 使用carousel:viewForItemAtIndex:reusingView:dataSource方法自動從傳遞到傳送帶 的第一個視圖導出。 您也可以使用carouselItemWidth:delegate 方法覆蓋此值,該方法將改變爲輪播項目分配的空間(但 不會調整或縮放項目視圖)。
問題2:
使用這個屬性對於分頁滾動:
@property (nonatomic, assign, getter = isPagingEnabled) BOOL pagingEnabled;
啓用和禁用分頁。當啓用分頁功能時,傳送帶將在用戶滾動時停止在每個項目視圖中,非常類似於UIScrollView的pagingEnabled屬性。
我試圖改變iCarousel,而看起來它不能平穩移動,如果我改變了itemWidth。
- 所以我試圖寫我自己的旋轉木馬,現在它的作品。感謝大家。
對於寬度,您可以使用委託方法「carouselItemWidth」並使用滾動速度在時間滾動1項目 –
「scrollspeed」不用於此目的親愛的@ saurabh-prajapati。 – mgyky
我使用了carouselItemWidth,它只能設置1個itemWidth,我想爲不同的item使用不同的itemWidth。 – James