diff --git a/doric-iOS/Pod/Classes/Shader/DoricSliderLayout.h b/doric-iOS/Pod/Classes/Shader/DoricSliderLayout.h index a9c39964..93a14d49 100644 --- a/doric-iOS/Pod/Classes/Shader/DoricSliderLayout.h +++ b/doric-iOS/Pod/Classes/Shader/DoricSliderLayout.h @@ -25,5 +25,6 @@ @property(nonatomic, assign) CGFloat galleryItemWidth; @property(nonatomic, assign) CGFloat galleryMinScale; @property(nonatomic, assign) CGFloat galleryMinAlpha; +@property(nonatomic, assign) BOOL enableGallery; @end diff --git a/doric-iOS/Pod/Classes/Shader/DoricSliderLayout.m b/doric-iOS/Pod/Classes/Shader/DoricSliderLayout.m index 1d685ea4..1332cc81 100644 --- a/doric-iOS/Pod/Classes/Shader/DoricSliderLayout.m +++ b/doric-iOS/Pod/Classes/Shader/DoricSliderLayout.m @@ -24,32 +24,36 @@ @implementation DoricSliderLayout - (NSArray *)layoutAttributesForElementsInRect:(CGRect)rect { - NSArray *attributes = [super layoutAttributesForElementsInRect:rect]; - CGRect visitRect = {self.collectionView.contentOffset,self.collectionView.bounds.size}; - NSMutableArray *attributesCopy = [NSMutableArray array]; - for (UICollectionViewLayoutAttributes *attribute in attributes) { - UICollectionViewLayoutAttributes *attributeCopy = [attribute copy]; - [attributesCopy addObject:attributeCopy]; - } - - for (UICollectionViewLayoutAttributes *attribute in attributesCopy) { - CGFloat distance = CGRectGetMidX(visitRect) - attribute.center.x; - float diff = fabs(distance); - CATransform3D scaleTransform = CATransform3DIdentity; - - if (diff >= 0 && diff <= self.galleryItemWidth) { - float scale = 1 - (1 - self.galleryMinScale) * (diff / self.galleryItemWidth); - scaleTransform = CATransform3DMakeScale(scale, scale, scale); - attribute.alpha = 1 - (1 - self.galleryMinAlpha) * (diff / self.galleryItemWidth); - } else { - float scale = self.galleryMinScale; - scaleTransform = CATransform3DMakeScale(scale, scale, scale); - attribute.alpha = self.galleryMinAlpha; + if (self.enableGallery) { + NSArray *attributes = [super layoutAttributesForElementsInRect:rect]; + CGRect visitRect = {self.collectionView.contentOffset, self.collectionView.bounds.size}; + NSMutableArray *attributesCopy = [NSMutableArray array]; + for (UICollectionViewLayoutAttributes *attribute in attributes) { + UICollectionViewLayoutAttributes *attributeCopy = [attribute copy]; + [attributesCopy addObject:attributeCopy]; } - attribute.transform3D = scaleTransform; + for (UICollectionViewLayoutAttributes *attribute in attributesCopy) { + CGFloat distance = CGRectGetMidX(visitRect) - attribute.center.x; + float diff = fabs(distance); + CATransform3D scaleTransform = CATransform3DIdentity; + + if (diff >= 0 && diff <= self.galleryItemWidth) { + float scale = 1 - (1 - self.galleryMinScale) * (diff / self.galleryItemWidth); + scaleTransform = CATransform3DMakeScale(scale, scale, scale); + attribute.alpha = 1 - (1 - self.galleryMinAlpha) * (diff / self.galleryItemWidth); + } else { + float scale = self.galleryMinScale; + scaleTransform = CATransform3DMakeScale(scale, scale, scale); + attribute.alpha = self.galleryMinAlpha; + } + + attribute.transform3D = scaleTransform; + } + return attributesCopy; + } else { + return [super layoutAttributesForElementsInRect:rect]; } - return attributesCopy; } - (BOOL)shouldInvalidateLayoutForBoundsChange:(CGRect)newBounds { diff --git a/doric-iOS/Pod/Classes/Shader/DoricSliderNode.m b/doric-iOS/Pod/Classes/Shader/DoricSliderNode.m index f464bda4..63151c05 100644 --- a/doric-iOS/Pod/Classes/Shader/DoricSliderNode.m +++ b/doric-iOS/Pod/Classes/Shader/DoricSliderNode.m @@ -131,6 +131,7 @@ - (void)blendView:(UICollectionView *)view forPropName:(NSString *)name propValu layout.galleryItemWidth = self.galleryItemWidth; layout.galleryMinScale = self.galleryMinScale; layout.galleryMinAlpha = self.galleryMinAlpha; + layout.enableGallery = YES; } } else if ([prop isKindOfClass:NSString.class]) {