实现卡片浏览时居中放大的效果。
STFlowLayout.h
#import <UIKit/UIKit.h>
NS_ASSUME_NONNULL_BEGIN
@interface STFlowLayout : UICollectionViewFlowLayout
@end
NS_ASSUME_NONNULL_END
STFlowLayout.m
#import "STFlowLayout.h"
@interface STFlowLayout()
@end
@implementation STFlowLayout
- (void)prepareLayout {
[super prepareLayout];
self.scrollDirection = UICollectionViewScrollDirectionHorizontal;
}
- (nullable NSArray<__kindof UICollectionViewLayoutAttributes *> *)layoutAttributesForElementsInRect:(CGRect)rect{
NSArray *arr = [super layoutAttributesForElementsInRect:rect];
CGFloat contentOffsetX = self.collectionView.contentOffset.x;
CGFloat collectionViewCenterX = self.collectionView.frame.size.width * 0.5;
for (UICollectionViewLayoutAttributes *attr in arr) {
CGFloat scale = 1 - fabs(attr.cente