Open jcamilorm902 opened 7 years ago
do you mean auto scrolling?
I am thinking about auto scrolling automatically, but every 3 seconds, 5 seconds, etc. without clicking, sliding or user interaction. Something like this:
when you create the iCarousel, there should be an autoscroll property you can set. Like this:
_carousel = new iCarousel { Autoscroll = 1.0f, };
1.0f means it scrolls up 1 item per second. Hope this helps!
PS: You should also make sure that you have wrapping enabled. Linear doesn't have wrapping enabled as a default, so you should override the ValueForOption method in the iCarouseldelegate
@Noomie Thank you! it is, but i found a couple of things, it does not work when carousel type is iCarouselTypeCoverFlow or iCarouselTypeLinear. And it does not stop in carousel item when autoscrolling, do you know why?
@jcamilorm902 As I mentioned, you need to enable wrapping for these carouseltypes. You need to create a customdelegate class for this to add to your carousel.
Here's an example:
public class CustomDelegate : iCarouselDelegate
{
private const float ShouldWrap = 1.0f;
public override nfloat ValueForOption(iCarousel carousel, iCarouselOption option, nfloat value)
{
if (option == iCarouselOption.Wrap)
{
return ShouldWrap;
}
}
Then add this to your carousel:
_carousel = new iCarousel
{
Delegate = new CustomDelegate(),
Autoscroll = 1.0f,
};
I know that it's possible to make it stop at each item (there's a pagingEnabled property for this when you create the carousel aswell), but I don't know if it's possible to automatically do this. Maybe try and go through the documentation to see if there's an option for this.
@Noomie Thank you!
I found an easier solution, instead using autoscroll which can't work with paging together:
__weak MyViewController * weakSelf = self;
[NSTimer scheduledTimerWithTimeInterval:2 repeats:YES block:^(NSTimer * _Nonnull timer) {
[weakSelf.carousel scrollByNumberOfItems:1 duration:0.3];
}];
Inspired by @maodd , I improved this method, which can automatically slide in the opposite direction when sliding to the end.
__weak MyViewController * weakSelf = self;
int index = 1
[NSTimer scheduledTimerWithTimeInterval:2 repeats:YES block:^(NSTimer * _Nonnull timer) {
if (weakSelf.currentItemIndex == weakSelf.numberOfItems-1) {
index = -1;
} else if (weakSelf.currentItemIndex == 0) {
index = 1;
}
[weakSelf scrollByNumberOfItems:index duration:0.3];
}];
or slide to first item
__weak MyViewController * weakSelf = self;
[NSTimer scheduledTimerWithTimeInterval:2 repeats:YES block:^(NSTimer * _Nonnull timer) {
if (weakSelf.currentItemIndex == weakSelf.numberOfItems-1) {
[weakSelf scrollToItemAtIndex:0 duration:0.1];
} else {
[weakSelf scrollByNumberOfItems:1 duration:0.3];
}
}];
Hi!
Is there any setting or something like that to set autoplay in icarousel?
Thanks!