2015-07-03 20 views
1

我正在與iCarousel - https://github.com/nicklockwood/iCarousel不同的寬度爲不同的項目 - 在iCarousel

雖然我需要更改不同項目的寬度,但意味着要爲不同的項目設置不同的寬度。

不確定如何進行更改,如果您對此有任何經驗,請幫助。

另一個問題是如何使它滾動時只滾動1項目。 - 表示只滾動到下一個項目,目前它會繼續滾動到下一個項目的下一個...

任何幫助,高度讚賞。

+0

對於寬度,您可以使用委託方法「carouselItemWidth」並使用滾動速度在時間滾動1項目 –

+0

「scrollspeed」不用於此目的親愛的@ saurabh-prajapati。 – mgyky

+0

我使用了carouselItemWidth,它只能設置1個itemWidth,我想爲不同的item使用不同的itemWidth。 – James

回答

2

因爲當滾動你必須添加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]; 
} 

工作我如預期的那樣。 希望這會幫助你..

+0

這個也適用於我,謝謝。 – James

+0

對於不同的項目,您對不同的itemWidth有任何想法嗎? – James

+0

不知道爲每個旋轉木馬項目設置不同大小的方法,但是如果您想在每個旋轉木馬項目上顯示具有動態大小的圖像(即圖像將適合屏幕),那麼我認爲您可以添加UIImageView和內容模式。這裏是鏈接http://stackoverflow.com/questions/12436178/image-is-not-fit-to-the-frame-of-uiimageview 你也可以通過設置他們的幀爲您的單個輪播項目中添加多個視圖需要, –

0

問題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屬性。

+0

我設置了carousel:viewForItemAtIndex:reusingView,但它無法爲每個視圖設置itemWidth。即使我設置了不同寬度的視圖,但它仍顯示相同的寬度(兩者之間有不同的空間)。 – James

+0

我也設置了pagingEnabled,雖然看起來不起作用,我是否需要設置其他屬性? – James

+0

爲什麼不嘗試這個分頁的例子:https://github.com/nicklockwood/iCarousel/tree/master/Examples/Paging%20Example – mgyky

0

我試圖改變iCarousel,而看起來它不能平穩移動,如果我改變了itemWidth。

- 所以我試圖寫我自己的旋轉木馬,現在它的作品。感謝大家。