iOS: add enable gallery
This commit is contained in:
parent
3393a474f9
commit
1b105d70e4
@ -25,5 +25,6 @@
|
|||||||
@property(nonatomic, assign) CGFloat galleryItemWidth;
|
@property(nonatomic, assign) CGFloat galleryItemWidth;
|
||||||
@property(nonatomic, assign) CGFloat galleryMinScale;
|
@property(nonatomic, assign) CGFloat galleryMinScale;
|
||||||
@property(nonatomic, assign) CGFloat galleryMinAlpha;
|
@property(nonatomic, assign) CGFloat galleryMinAlpha;
|
||||||
|
@property(nonatomic, assign) BOOL enableGallery;
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
@ -24,32 +24,36 @@
|
|||||||
@implementation DoricSliderLayout
|
@implementation DoricSliderLayout
|
||||||
|
|
||||||
- (NSArray<UICollectionViewLayoutAttributes *> *)layoutAttributesForElementsInRect:(CGRect)rect {
|
- (NSArray<UICollectionViewLayoutAttributes *> *)layoutAttributesForElementsInRect:(CGRect)rect {
|
||||||
NSArray *attributes = [super layoutAttributesForElementsInRect:rect];
|
if (self.enableGallery) {
|
||||||
CGRect visitRect = {self.collectionView.contentOffset,self.collectionView.bounds.size};
|
NSArray *attributes = [super layoutAttributesForElementsInRect:rect];
|
||||||
NSMutableArray *attributesCopy = [NSMutableArray array];
|
CGRect visitRect = {self.collectionView.contentOffset, self.collectionView.bounds.size};
|
||||||
for (UICollectionViewLayoutAttributes *attribute in attributes) {
|
NSMutableArray *attributesCopy = [NSMutableArray array];
|
||||||
UICollectionViewLayoutAttributes *attributeCopy = [attribute copy];
|
for (UICollectionViewLayoutAttributes *attribute in attributes) {
|
||||||
[attributesCopy addObject:attributeCopy];
|
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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 {
|
- (BOOL)shouldInvalidateLayoutForBoundsChange:(CGRect)newBounds {
|
||||||
|
@ -131,6 +131,7 @@ - (void)blendView:(UICollectionView *)view forPropName:(NSString *)name propValu
|
|||||||
layout.galleryItemWidth = self.galleryItemWidth;
|
layout.galleryItemWidth = self.galleryItemWidth;
|
||||||
layout.galleryMinScale = self.galleryMinScale;
|
layout.galleryMinScale = self.galleryMinScale;
|
||||||
layout.galleryMinAlpha = self.galleryMinAlpha;
|
layout.galleryMinAlpha = self.galleryMinAlpha;
|
||||||
|
layout.enableGallery = YES;
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if ([prop isKindOfClass:NSString.class]) {
|
} else if ([prop isKindOfClass:NSString.class]) {
|
||||||
|
Reference in New Issue
Block a user