不同项目的不同宽度 - 在 iCarousel 中

different width for different item - in iCarousel

我正在使用 iCarousel - https://github.com/nicklockwood/iCarousel

虽然我需要改变不同项目的宽度,意思是为不同的项目制作不同的宽度。

不知道怎么改,有这方面经验的请帮忙

另一个问题是如何让它在滚动时只滚动1个项目。 -- 表示只滚动到下一个项目,目前它将继续滚动到下一个项目的下一个...

非常感谢任何帮助。

问题 1

在 iCarousel itemWidth 属性 中是只读的,您应该为此目的使用 carousel:viewForItemAtIndex:reusingView:

@property (nonatomic, readonly) CGFloat itemWidth;

The display width of items in the carousel (read only). This is derived automatically from the first view passed in to the carousel using the carousel:viewForItemAtIndex:reusingView: dataSource method. You can also override this value using the carouselItemWidth: delegate method, which will alter the space allocated for carousel items (but won't resize or scale the item views).

问题 2 :

使用此 属性 进行分页滚动:

@property (nonatomic, assign, getter = isPagingEnabled) BOOL pagingEnabled;

Enables and disables paging. When paging is enabled, the carousel will stop at each item view as the user scrolls, much like the pagingEnabled property of a UIScrollView.

滚动时仅滚动 1 个项目,您必须添加 gestureRecognizer 并禁用 Carousel 的滚动

_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];

向左滑动: & 向右滑动: 将变为

-(void)swipeleft:(UISwipeGestureRecognizer*)gestureRecognizer
{ 
    [_myCarousel scrollByNumberOfItems:1 duration:0.25];
}
-(void)swiperight:(UISwipeGestureRecognizer*)gestureRecognizer
{
    [_myCarousel scrollByNumberOfItems:-1 duration:0.25];
}

按预期为我工作。 希望对你有所帮助..

我试着改变了iCarousel,但是如果我改变了itemWidth 看起来它不能顺畅移动。

-- 所以我试着写了自己的轮播,现在可以了。谢谢大家。