OGeek|极客世界-中国程序员成长平台

标题: ios - 不同项目的不同宽度 - 在 iCarousel 中 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-12 15:42
标题: ios - 不同项目的不同宽度 - 在 iCarousel 中

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

虽然我需要更改不同项目的宽度,但意味着为不同的项目设置不同的宽度。

不确定如何进行更改,如果您对此有任何经验,请提供帮助。

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

非常感谢任何帮助。



Best Answer-推荐答案


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

_myCarousel = [[iCarousel alloc] initWithFrame:CGRectMake(0,0, 310, 100)];
_myCarousel.type = iCarouselTypeCoverFlow2;                         
_myCarousel.scrollEnabled = NO;

UISwipeGestureRecognizer * swipeleft = [[UISwipeGestureRecognizer alloc] initWithTarget:self actionselector(swipeleft];
swipeleft.direction = UISwipeGestureRecognizerDirectionLeft;
[_myCarousel addGestureRecognizer:swipeleft];

UISwipeGestureRecognizer * swiperight = [[UISwipeGestureRecognizer alloc] initWithTarget:self actionselector(swiperight];
swiperight.direction=UISwipeGestureRecognizerDirectionRight;
[_myCarousel addGestureRecognizer:swiperight];

_myCarousel.dataSource = self;
_myCarousel.delegate = self;
[myView addSubview:_myCarousel];

swipeleft: & swiperight: 将是

-(void)swipeleftUISwipeGestureRecognizer*)gestureRecognizer
{ 
    [_myCarousel scrollByNumberOfItems:1 duration:0.25];
}
-(void)swiperightUISwipeGestureRecognizer*)gestureRecognizer
{
    [_myCarousel scrollByNumberOfItems:-1 duration:0.25];
}

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

关于ios - 不同项目的不同宽度 - 在 iCarousel 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31205529/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://sqlite.in/) Powered by Discuz! X3.4