- (void)updateNumberOfVisibleItems
{
//get number of visible items
switch (_type)
{
case iCarouselTypeLinear:
{
//exact number required to fill screen
CGFloat spacing = [self valueForOption:iCarouselOptionSpacing withDefault:1.0];
CGFloat width = _vertical ? self.bounds.size.height: self.bounds.size.width;
CGFloat itemWidth = _itemWidth * spacing;
_numberOfVisibleItems = ceil(width / itemWidth) + 2;
break;
}
case iCarouselTypeCoverFlow:
case iCarouselTypeCoverFlow2:
{
//exact number required to fill screen
CGFloat spacing = [self valueForOption:iCarouselOptionSpacing withDefault:0.25];
CGFloat width = _vertical ? self.bounds.size.height: self.bounds.size.width;
CGFloat itemWidth = _itemWidth * spacing;
_numberOfVisibleItems = ceil(width / itemWidth) + 2;
break;
}
#warning -只显示多少个item 隐藏多余的 根据要展示的type里面修改
case iCarouselTypeRotary:
{
_numberOfVisibleItems = MIN(MAX_VISIBLE_ITEMS, _numberOfVisibleItems);
_numberOfVisibleItems = [self valueForOption:iCarouselOptionVisibleItems withDefault:_numberOfVisibleItems];
_numberOfVisibleItems = 3; // <-- 这里修改需要展示的个数
}
case iCarouselTypeCylinder:
{
//based on count value
_numberOfVisibleItems = [self circularCarouselItemCount];
break;
}
case iCarouselTypeInvertedRotary:
case iCarouselTypeInvertedCylinder:
{
//TODO: improve this
_numberOfVisibleItems = ceil([self circularCarouselItemCount] / 2.0);
break;
}
case iCarouselTypeWheel:
case iCarouselTypeInvertedWheel:
{
//TODO: improve this
CGFloat count = [self circularCarouselItemCount];
CGFloat spacing = [self valueForOption:iCarouselOptionSpacing withDefault:1.0];
CGFloat arc = [self valueForOption:iCarouselOptionArc withDefault:M_PI * 2.0];
CGFloat radius = [self valueForOption:iCarouselOptionRadius withDefault:_itemWidth * spacing * count / arc];
if (radius - _itemWidth / 2.0 < MIN(self.bounds.size.width, self.bounds.size.height) / 2.0)
{
_numberOfVisibleItems = count;
}
else
{
_numberOfVisibleItems = ceil(count / 2.0) + 1;
}
break;
}
case iCarouselTypeTimeMachine:
case iCarouselTypeInvertedTimeMachine:
case iCarouselTypeCustom:
{
//slightly arbitrary number, chosen for performance reasons
_numberOfVisibleItems = MAX_VISIBLE_ITEMS;
break;
}
}
_numberOfVisibleItems = MIN(MAX_VISIBLE_ITEMS, _numberOfVisibleItems);
_numberOfVisibleItems = [self valueForOption:iCarouselOptionVisibleItems withDefault:_numberOfVisibleItems];
_numberOfVisibleItems = MAX(0, MIN(_numberOfVisibleItems, _numberOfItems + _numberOfPlaceholdersToShow));
}