From 2728afffff2e60bd0bbcf14ef8819732c5f81506 Mon Sep 17 00:00:00 2001 From: Andy Martin Date: Fri, 17 Jul 2015 14:10:24 -0700 Subject: [PATCH] added the ability to specify the max and min opacity of the carousel --- iCarousel/iCarousel.h | 3 ++- iCarousel/iCarousel.m | 17 ++++++++++++++--- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/iCarousel/iCarousel.h b/iCarousel/iCarousel.h index 53350915d1..7f79eee6bf 100644 --- a/iCarousel/iCarousel.h +++ b/iCarousel/iCarousel.h @@ -95,7 +95,8 @@ typedef NS_ENUM(NSInteger, iCarouselOption) iCarouselOptionFadeMin, iCarouselOptionFadeMax, iCarouselOptionFadeRange, - iCarouselOptionFadeMinAlpha + iCarouselOptionMinOpacity, + iCarouselOptionMaxOpacity }; diff --git a/iCarousel/iCarousel.m b/iCarousel/iCarousel.m index 396c19451b..5801427b62 100644 --- a/iCarousel/iCarousel.m +++ b/iCarousel/iCarousel.m @@ -437,7 +437,8 @@ - (CGFloat)alphaForItemWithOffset:(CGFloat)offset CGFloat fadeMin = -INFINITY; CGFloat fadeMax = INFINITY; CGFloat fadeRange = 1.0; - CGFloat fadeMinAlpha = 0.0; + CGFloat minOpacity = 0.0; + CGFloat maxOpacity = 1.0; switch (_type) { case iCarouselTypeTimeMachine: @@ -467,7 +468,8 @@ - (CGFloat)alphaForItemWithOffset:(CGFloat)offset fadeMin = [self valueForOption:iCarouselOptionFadeMin withDefault:fadeMin]; fadeMax = [self valueForOption:iCarouselOptionFadeMax withDefault:fadeMax]; fadeRange = [self valueForOption:iCarouselOptionFadeRange withDefault:fadeRange]; - fadeMinAlpha = [self valueForOption:iCarouselOptionFadeMinAlpha withDefault:fadeMinAlpha]; + minOpacity = [self valueForOption:iCarouselOptionMinOpacity withDefault:minOpacity]; + maxOpacity = [self valueForOption:iCarouselOptionMaxOpacity withDefault:maxOpacity]; #ifdef ICAROUSEL_MACOS @@ -488,7 +490,16 @@ - (CGFloat)alphaForItemWithOffset:(CGFloat)offset { factor = fadeMin - offset; } - return 1.0 - MIN(factor, fadeRange) / fadeRange * (1.0 - fadeMinAlpha); + + if(factor == 0.0) + { + return 1.0; + } + else + { + double fadeAmount = (MIN(factor, fadeRange) / fadeRange); + return MAX( MIN(1.0 - fadeAmount, maxOpacity), minOpacity); + } } - (CGFloat)valueForOption:(iCarouselOption)option withDefault:(CGFloat)value