Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion TYCyclePagerView.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ s.license = { :type => 'MIT', :file => 'LICENSE' }
s.author = { "tany" => "[email protected]" }
# 作者主页 s.social_media_url =""
# 代码库最低支持的版本
s.platform = :ios, "7.0"
s.platform = :ios, "11.0"
# 代码的Clone 地址 和 tag 版本
s.source = { :git => "https://github.com/12207480/TYCyclePagerView.git", :tag => s.version.to_s }
# 如果使用pod 需要导入哪些资源
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>
Binary file not shown.
4 changes: 2 additions & 2 deletions TYCyclePagerViewDemo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
DEVELOPMENT_TEAM = 7RMEVM26EB;
INFOPLIST_FILE = TYCyclePagerViewDemo/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 7.0;
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.tany.TYCyclePagerViewDemo;
PRODUCT_NAME = "$(TARGET_NAME)";
Expand All @@ -402,7 +402,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
DEVELOPMENT_TEAM = 7RMEVM26EB;
INFOPLIST_FILE = TYCyclePagerViewDemo/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 7.0;
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.tany.TYCyclePagerViewDemo;
PRODUCT_NAME = "$(TARGET_NAME)";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>
Binary file not shown.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>SchemeUserState</key>
<dict>
<key>TYCyclePagerViewDemo.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>0</integer>
</dict>
</dict>
</dict>
</plist>
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ typedef NS_ENUM(NSUInteger, TYCyclePagerTransformLayoutType) {
TYCyclePagerTransformLayoutCoverflow,
};

/// 滚动方向
typedef NS_ENUM(NSUInteger, TYCyclePagerScrollDirection) {
TYCyclePagerScrollDirectionHorizontal,
TYCyclePagerScrollDirectionVertical
};

@class TYCyclePagerTransformLayout;
@protocol TYCyclePagerTransformLayoutDelegate <NSObject>

Expand Down Expand Up @@ -44,6 +50,9 @@ typedef NS_ENUM(NSUInteger, TYCyclePagerTransformLayoutType) {
@property (nonatomic, assign) CGFloat rateOfChange; // scale and angle change rate
@property (nonatomic, assign) BOOL adjustSpacingWhenScroling;

/// 滚动方向,默认MFBannerViewScrollDirectionHorizontal水平滚动
@property (nonatomic, assign) TYCyclePagerScrollDirection scrollDirection;

/**
pageView cell item vertical centering
*/
Expand Down
158 changes: 136 additions & 22 deletions TYCyclePagerViewDemo/TYCyclePagerView/TYCyclePagerTransformLayout.m
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ - (void)setLayout:(TYCyclePagerViewLayout *)layout {
self.itemSize = _layout.itemSize;
self.minimumInteritemSpacing = _layout.itemSpacing;
self.minimumLineSpacing = _layout.itemSpacing;
if (_layout.scrollDirection == TYCyclePagerScrollDirectionHorizontal) {
self.scrollDirection = UICollectionViewScrollDirectionHorizontal;
} else {
self.scrollDirection = UICollectionViewScrollDirectionVertical;
}
}

- (CGSize)itemSize {
Expand All @@ -87,9 +92,24 @@ - (CGFloat)minimumInteritemSpacing {
return _layout.itemSpacing;
}

- (TYTransformLayoutItemDirection)directionWithCenterX:(CGFloat)centerX {
- (TYTransformLayoutItemDirection)directionWithCenter:(CGPoint)center {
TYTransformLayoutItemDirection direction= TYTransformLayoutItemRight;

if (self.scrollDirection == UICollectionViewScrollDirectionVertical) {

CGFloat centerY = center.y;
CGFloat contentCenterY = self.collectionView.contentOffset.y + CGRectGetHeight(self.collectionView.frame)/2;
if (ABS(centerY - contentCenterY) < 0.5) {
direction = TYTransformLayoutItemCenter;
}else if (centerY - contentCenterY < 0) {
direction = TYTransformLayoutItemLeft;
}
return direction;

}

CGFloat contentCenterX = self.collectionView.contentOffset.x + CGRectGetWidth(self.collectionView.frame)/2;
CGFloat centerX = center.x;
if (ABS(centerX - contentCenterX) < 0.5) {
direction = TYTransformLayoutItemCenter;
}else if (centerX - contentCenterX < 0) {
Expand Down Expand Up @@ -167,6 +187,19 @@ - (void)applyTransformToAttributes:(UICollectionViewLayoutAttributes *)attribute
#pragma mark - LinearTransform

- (void)applyLinearTransformToAttributes:(UICollectionViewLayoutAttributes *)attributes {

if (self.scrollDirection == UICollectionViewScrollDirectionVertical) {
CGFloat collectionHeight = self.collectionView.frame.size.height;
if (collectionHeight <= 0) {
return;
}
CGFloat centetY = self.collectionView.contentOffset.y + collectionHeight/2;
CGFloat delta = ABS(attributes.center.y - centetY);
CGFloat scale = MAX(1 - delta/collectionHeight*_layout.rateOfChange, _layout.minimumScale);
CGFloat alpha = MAX(1 - delta/collectionHeight, _layout.minimumAlpha);
[self applyLinearTransformToAttributes:attributes scale:scale alpha:alpha];
}

CGFloat collectionViewWidth = self.collectionView.frame.size.width;
if (collectionViewWidth <= 0) {
return;
Expand All @@ -181,22 +214,34 @@ - (void)applyLinearTransformToAttributes:(UICollectionViewLayoutAttributes *)att
- (void)applyLinearTransformToAttributes:(UICollectionViewLayoutAttributes *)attributes scale:(CGFloat)scale alpha:(CGFloat)alpha {
CGAffineTransform transform = CGAffineTransformMakeScale(scale, scale);
if (_layout.adjustSpacingWhenScroling) {
TYTransformLayoutItemDirection direction = [self directionWithCenterX:attributes.center.x];
TYTransformLayoutItemDirection direction = [self directionWithCenter:attributes.center];
CGFloat translate = 0;
switch (direction) {
case TYTransformLayoutItemLeft:
translate = 1.15 * attributes.size.width*(1-scale)/2;
if (self.scrollDirection == UICollectionViewScrollDirectionVertical) {
translate = 1.15 * attributes.size.height*(1-scale)/2;
} else {
translate = 1.15 * attributes.size.width*(1-scale)/2;
}
break;
case TYTransformLayoutItemRight:
translate = -1.15 * attributes.size.width*(1-scale)/2;
if (self.scrollDirection == UICollectionViewScrollDirectionVertical) {
translate = -1.15 * attributes.size.height*(1-scale)/2;
} else {
translate = -1.15 * attributes.size.width*(1-scale)/2;
}
break;
default:
// center
scale = 1.0;
alpha = 1.0;
break;
}
transform = CGAffineTransformTranslate(transform,translate, 0);
if (self.scrollDirection == UICollectionViewScrollDirectionVertical) {
transform = CGAffineTransformTranslate(transform,0, translate);
} else {
transform = CGAffineTransformTranslate(transform,translate, 0);
}
}
attributes.transform = transform;
attributes.alpha = alpha;
Expand All @@ -205,6 +250,21 @@ - (void)applyLinearTransformToAttributes:(UICollectionViewLayoutAttributes *)att
#pragma mark - CoverflowTransform

- (void)applyCoverflowTransformToAttributes:(UICollectionViewLayoutAttributes *)attributes{

if (self.scrollDirection == UICollectionViewScrollDirectionVertical) {

CGFloat collectionViewHeight = self.collectionView.frame.size.height;
if (collectionViewHeight <= 0) {
return;
}
CGFloat centetY = self.collectionView.contentOffset.y + collectionViewHeight/2;
CGFloat delta = ABS(attributes.center.y - centetY);
CGFloat angle = MIN(delta/collectionViewHeight*(1-_layout.rateOfChange), _layout.maximumAngle);
CGFloat alpha = MAX(1 - delta/collectionViewHeight, _layout.minimumAlpha);
[self applyCoverflowTransformToAttributes:attributes angle:angle alpha:alpha];

}

CGFloat collectionViewWidth = self.collectionView.frame.size.width;
if (collectionViewWidth <= 0) {
return;
Expand All @@ -217,16 +277,24 @@ - (void)applyCoverflowTransformToAttributes:(UICollectionViewLayoutAttributes *)
}

- (void)applyCoverflowTransformToAttributes:(UICollectionViewLayoutAttributes *)attributes angle:(CGFloat)angle alpha:(CGFloat)alpha {
TYTransformLayoutItemDirection direction = [self directionWithCenterX:attributes.center.x];
TYTransformLayoutItemDirection direction = [self directionWithCenter:attributes.center];
CATransform3D transform3D = CATransform3DIdentity;
transform3D.m34 = -0.002;
CGFloat translate = 0;
switch (direction) {
case TYTransformLayoutItemLeft:
translate = (1-cos(angle*1.2*M_PI))*attributes.size.width;
if (self.scrollDirection == UICollectionViewScrollDirectionVertical) {
translate = (1-cos(angle*1.2*M_PI))*attributes.size.height;
} else {
translate = (1-cos(angle*1.2*M_PI))*attributes.size.width;
}
break;
case TYTransformLayoutItemRight:
translate = -(1-cos(angle*1.2*M_PI))*attributes.size.width;
if (self.scrollDirection == UICollectionViewScrollDirectionVertical) {
translate = -(1-cos(angle*1.2*M_PI))*attributes.size.height;
} else {
translate = -(1-cos(angle*1.2*M_PI))*attributes.size.width;
}
angle = -angle;
break;
default:
Expand All @@ -235,10 +303,18 @@ - (void)applyCoverflowTransformToAttributes:(UICollectionViewLayoutAttributes *)
alpha = 1;
break;
}

transform3D = CATransform3DRotate(transform3D, M_PI*angle, 0, 1, 0);

if (self.scrollDirection == UICollectionViewScrollDirectionVertical) {
transform3D = CATransform3DRotate(transform3D, M_PI*angle, 1, 0, 0);
} else {
transform3D = CATransform3DRotate(transform3D, M_PI*angle, 0, 1, 0);
}
if (_layout.adjustSpacingWhenScroling) {
transform3D = CATransform3DTranslate(transform3D, translate, 0, 0);
if (self.scrollDirection == UICollectionViewScrollDirectionVertical) {
transform3D = CATransform3DTranslate(transform3D, 0, translate, 0);
} else {
transform3D = CATransform3DTranslate(transform3D, translate, 0, 0);
}
}
attributes.transform3D = transform3D;
attributes.alpha = alpha;
Expand All @@ -257,13 +333,25 @@ - (instancetype)init {
_maximumAngle = 0.2;
_rateOfChange = 0.4;
_adjustSpacingWhenScroling = YES;
_scrollDirection = TYCyclePagerScrollDirectionHorizontal;
}
return self;
}

#pragma mark - getter

- (UIEdgeInsets)onlyOneSectionInset {

if (_scrollDirection == TYCyclePagerScrollDirectionVertical) {
CGFloat bottomSpace = _pageView && !_isInfiniteLoop && _itemVerticalCenter ? (CGRectGetHeight(_pageView.frame) - _itemSize.height)/2 : _sectionInset.bottom;
CGFloat topSpace = _pageView && !_isInfiniteLoop && _itemVerticalCenter ? (CGRectGetHeight(_pageView.frame) - _itemSize.height)/2 : _sectionInset.top;
if (_itemHorizontalCenter) {
CGFloat horizontalSpace = (CGRectGetWidth(_pageView.frame) - _itemSize.width)/2;
return UIEdgeInsetsMake(topSpace, horizontalSpace, bottomSpace, horizontalSpace);
}
return UIEdgeInsetsMake(topSpace, _sectionInset.left, bottomSpace, _sectionInset.right);
}

CGFloat leftSpace = _pageView && !_isInfiniteLoop && _itemHorizontalCenter ? (CGRectGetWidth(_pageView.frame) - _itemSize.width)/2 : _sectionInset.left;
CGFloat rightSpace = _pageView && !_isInfiniteLoop && _itemHorizontalCenter ? (CGRectGetWidth(_pageView.frame) - _itemSize.width)/2 : _sectionInset.right;
if (_itemVerticalCenter) {
Expand All @@ -274,25 +362,51 @@ - (UIEdgeInsets)onlyOneSectionInset {
}

- (UIEdgeInsets)firstSectionInset {
if (_itemVerticalCenter) {
CGFloat verticalSpace = (CGRectGetHeight(_pageView.frame) - _itemSize.height)/2;
return UIEdgeInsetsMake(verticalSpace, _sectionInset.left, verticalSpace, _itemSpacing);

if (_scrollDirection == TYCyclePagerScrollDirectionVertical) {
if (_itemHorizontalCenter) {
CGFloat horizontalSpace = (CGRectGetWidth(_pageView.frame) - _itemSize.width)/2;
return UIEdgeInsetsMake(_sectionInset.top, horizontalSpace, _itemSpacing, horizontalSpace);
}
return UIEdgeInsetsMake(_sectionInset.top, _sectionInset.left, _itemSpacing, _sectionInset.right);
} else {
if (_itemVerticalCenter) {
CGFloat verticalSpace = (CGRectGetHeight(_pageView.frame) - _itemSize.height)/2;
return UIEdgeInsetsMake(verticalSpace, _sectionInset.left, verticalSpace, _itemSpacing);
}
return UIEdgeInsetsMake(_sectionInset.top, _sectionInset.left, _sectionInset.bottom, _itemSpacing);
}
return UIEdgeInsetsMake(_sectionInset.top, _sectionInset.left, _sectionInset.bottom, _itemSpacing);
}

- (UIEdgeInsets)lastSectionInset {
if (_itemVerticalCenter) {
CGFloat verticalSpace = (CGRectGetHeight(_pageView.frame) - _itemSize.height)/2;
return UIEdgeInsetsMake(verticalSpace, 0, verticalSpace, _sectionInset.right);

if (_scrollDirection == TYCyclePagerScrollDirectionVertical) {
if (_itemHorizontalCenter) {
CGFloat horizontalSpace = (CGRectGetWidth(_pageView.frame) - _itemSize.width)/2;
return UIEdgeInsetsMake(0, horizontalSpace, _sectionInset.bottom, horizontalSpace);
}
return UIEdgeInsetsMake(0, _sectionInset.left, _sectionInset.bottom, _sectionInset.right);
} else {
if (_itemVerticalCenter) {
CGFloat horizontalSpace = (CGRectGetWidth(_pageView.frame) - _itemSize.width)/2;
return UIEdgeInsetsMake(0, horizontalSpace, _sectionInset.bottom, horizontalSpace);
}
return UIEdgeInsetsMake(_sectionInset.top, 0, _sectionInset.bottom, _sectionInset.right);
}
return UIEdgeInsetsMake(_sectionInset.top, 0, _sectionInset.bottom, _sectionInset.right);
}

- (UIEdgeInsets)middleSectionInset {
if (_itemVerticalCenter) {
CGFloat verticalSpace = (CGRectGetHeight(_pageView.frame) - _itemSize.height)/2;
return UIEdgeInsetsMake(verticalSpace, 0, verticalSpace, _itemSpacing);

if (_scrollDirection == TYCyclePagerScrollDirectionVertical) {
if (_itemHorizontalCenter) {
CGFloat horizontalSpace = (CGRectGetWidth(_pageView.frame) - _itemSize.width)/2;
return UIEdgeInsetsMake(0, horizontalSpace, _itemSpacing, horizontalSpace);
}
} else {
if (_itemVerticalCenter) {
CGFloat verticalSpace = (CGRectGetHeight(_pageView.frame) - _itemSize.height)/2;
return UIEdgeInsetsMake(verticalSpace, 0, verticalSpace, _itemSpacing);
}
}
return _sectionInset;
}
Expand Down
16 changes: 9 additions & 7 deletions TYCyclePagerViewDemo/TYCyclePagerView/TYCyclePagerView.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,16 @@
//

#import <UIKit/UIKit.h>
#if __has_include(<TYCyclePagerView/TYCyclePagerView.h>)
#import <TYCyclePagerView/TYCyclePagerTransformLayout.h>
#else
#import "TYCyclePagerTransformLayout.h"
#endif
#if __has_include(<TYCyclePagerView/TYPageControl.h>)
#import <TYCyclePagerView/TYPageControl.h>
#endif
#import "TYPageControl.h"
//#if __has_include(<TYCyclePagerView/TYCyclePagerView.h>)
//#import <TYCyclePagerView/TYCyclePagerTransformLayout.h>
//#else
//#import "TYCyclePagerTransformLayout.h"
//#endif
//#if __has_include(<TYCyclePagerView/TYPageControl.h>)
//#import <TYCyclePagerView/TYPageControl.h>
//#endif

NS_ASSUME_NONNULL_BEGIN

Expand Down
Loading