2
votes

I am working with iCarousel - https://github.com/nicklockwood/iCarousel.

While I need to change the width of different items, means to make different width for different items.

Not sure how to make the change, please help if you have any experience on this one.

Another question is how to make it only scroll 1 item when scroll. -- means only scroll to next item, currently it will continue scroll to next of next items...

Any help is highly appreciated.

3
for width you can use delegate method "carouselItemWidth" and use scrollspeed to scroll 1 item at timeSaurabh Prajapati
"scrollspeed" not used for this purpose dear @saurabh-prajapati.mgyky
I used the carouselItemWidth, it can only set 1 itemWidth, I want to use different itemWidth for different item.James

3 Answers

2
votes

For only scroll 1 item when scroll you have to add gestureRecognizer & disable Carousel's scroll

_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: will be as

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

Working for me as expected. Hope this will help you..

0
votes

Question 1 :

in iCarousel itemWidth property is read-only you should use carousel:viewForItemAtIndex:reusingView for this purpose :

@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).

Question 2 :

use this property for scrolling with paging :

@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.

0
votes

I tried to change the iCarousel, while looks it cannot move smoothly if I changed the itemWidth.

-- So I tried to write my own carousel, and it works now. Thanks, everyone.