2

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.

MGY
  • 7,245
  • 5
  • 41
  • 74
James
  • 227
  • 1
  • 2
  • 11

3 Answers3

2

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

Haripal Wagh
  • 572
  • 1
  • 5
  • 18
  • Do you have any ideas on the different itemWidth for different items? – James Jul 05 '15 at 03:41
  • Dont know method for setting different size for each carousel item, but If you want to show image on each carousel item with dynamic size (i.e. Image will fit in screen) then I think you can add UIImageView and content mode. Here is link http://stackoverflow.com/questions/12436178/image-is-not-fit-to-the-frame-of-uiimageview Also you can add multiple views in single carousel item by setting their frames as per your need, – Haripal Wagh Jul 05 '15 at 05:51
0

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.

MGY
  • 7,245
  • 5
  • 41
  • 74
  • I set carousel:viewForItemAtIndex:reusingView, while it cannot set the itemWidth for each view. Even I set views with different width, while it still shows the same width (with different spaces between). – James Jul 03 '15 at 13:43
  • I set pagingEnabled too, while looks it does not work, do I need to set other properties? – James Jul 03 '15 at 13:44
  • Why not trying this example for paging : https://github.com/nicklockwood/iCarousel/tree/master/Examples/Paging%20Example – MGY Jul 03 '15 at 13:46
  • That does not work, I want something like the camera app in iPhone, it can just scroll for 1 item each time. – James Jul 03 '15 at 14:50
0

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.

James
  • 227
  • 1
  • 2
  • 11