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
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.
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>TYPagerControllerDemo.xcscheme</key>
<dict>
<key>orderHint</key>
<integer>0</integer>
</dict>
</dict>
</dict>
</plist>
4 changes: 2 additions & 2 deletions TYPagerControllerDemo/TYPagerController/TYPagerView.m
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ @interface TYPagerView ()<TYPagerViewLayoutDataSource, TYPagerViewLayoutDelegate

@end

@implementation TYPagerView

@implementation TYPagerView {
}
#pragma mark - life cycle

- (instancetype)initWithFrame:(CGRect)frame {
Expand Down
4 changes: 2 additions & 2 deletions TYPagerControllerDemo/TYPagerController/TYPagerViewLayout.m
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ - (void)configurePropertys {
_didLayoutSubViews = NO;
_firstScrollToIndex = 0;
_prefetchItemWillAddToSuperView = NO;
_addVisibleItemOnlyWhenScrollAnimatedEnd = NO;
_addVisibleItemOnlyWhenScrollAnimatedEnd = YES;
_progressAnimateEnabel = YES;
_adjustScrollViewInset = YES;
_scrollAnimated = YES;
Expand Down Expand Up @@ -278,7 +278,7 @@ - (void)scrollToItemAtIndex:(NSInteger)index animate:(BOOL)animate {
}

[self scrollViewWillScrollToView:_scrollView animate:animate];
[_scrollView setContentOffset:CGPointMake(index * CGRectGetWidth(_scrollView.frame),0) animated:NO];
[_scrollView setContentOffset:CGPointMake(index * CGRectGetWidth(_scrollView.frame),0) animated:animate];
[self scrollViewDidScrollToView:_scrollView animate:animate];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ - (void)addCollectionView {

- (void)addUnderLineView {
UIView *progressView = [[UIView alloc]init];
progressView.backgroundColor = [UIColor redColor];
progressView.userInteractionEnabled = NO;
[_collectionView addSubview:progressView];
_progressView = progressView;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ typedef NS_ENUM(NSUInteger, TYPagerBarStyle) {
TYPagerBarStyleProgressBounceView,
TYPagerBarStyleProgressElasticView,
TYPagerBarStyleCoverView,
TYPagerBarStyleHalfArcView,
};

@class TYTabPagerBar;
Expand Down Expand Up @@ -58,6 +59,9 @@ typedef NS_ENUM(NSUInteger, TYPagerBarStyle) {
// animate duration
@property (nonatomic, assign) CGFloat animateDuration; // default 0.3


@property (nonatomic, strong) UIColor *HalfArcColor;

- (instancetype)init NS_UNAVAILABLE;
+ (instancetype)new NS_UNAVAILABLE;

Expand Down
127 changes: 111 additions & 16 deletions TYPagerControllerDemo/TYPagerController/TabPager/TYTabPagerBarLayout.m
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ @interface TYTabPagerBarLayout ()
@end

#define kUnderLineViewHeight 2
#define kHalfArcProgressViewLineHeight 1

@implementation TYTabPagerBarLayout

Expand Down Expand Up @@ -128,6 +129,8 @@ - (void)setBarStyle:(TYPagerBarStyle)barStyle
self.progressHorEdging = -self.progressHeight/4;
self.progressVerEdging = 3;
break;
case TYPagerBarStyleHalfArcView:
break;
default:
break;
}
Expand Down Expand Up @@ -191,6 +194,9 @@ - (void)adjustContentCellsCenterInBar {
}

- (CGRect)cellFrameWithIndex:(NSInteger)index {
if (index >= self.pagerTabBar.countOfItems || index < 0) {
index = 0;
}
return [_pagerTabBar cellFrameWithIndex:index];
}

Expand All @@ -212,14 +218,17 @@ - (void)transitionFromCell:(UICollectionViewCell<TYTabPagerBarCellProtocol> *)fr
toCell.transform = CGAffineTransformIdentity;
}
};
if (animate) {
[UIView animateWithDuration:_animateDuration animations:^{
animateBlock();
}];
}else{
if (_barStyle == TYPagerBarStyleHalfArcView) {
animateBlock();
}else {
if (animate) {
[UIView animateWithDuration:_animateDuration animations:^{
animateBlock();
}];
}else{
animateBlock();
}
}

}

- (void)transitionFromCell:(UICollectionViewCell<TYTabPagerBarCellProtocol> *)fromCell toCell:(UICollectionViewCell<TYTabPagerBarCellProtocol> *)toCell progress:(CGFloat)progress {
Expand Down Expand Up @@ -258,17 +267,100 @@ - (void)setUnderLineFrameWithIndex:(NSInteger)index animated:(BOOL)animated
CGFloat progressHorEdging = _progressWidth > 0 ? (cellFrame.size.width - _progressWidth)/2 : _progressHorEdging;
CGFloat progressX = cellFrame.origin.x+progressHorEdging;
CGFloat progressY = _barStyle == TYPagerBarStyleCoverView ? (cellFrame.size.height - _progressHeight)/2:(cellFrame.size.height - _progressHeight - _progressVerEdging);
CGFloat width = cellFrame.size.width-2*progressHorEdging;

if (animated) {
[UIView animateWithDuration:_animateDuration animations:^{
progressView.frame = CGRectMake(progressX, progressY, width, _progressHeight);
}];
CGFloat width = cellFrame.size.width-2 * progressHorEdging;
if (_barStyle == TYPagerBarStyleHalfArcView) {
[self creatHalfArcProgressViewWithIndex:index originView:progressView];
}else {
progressView.frame = CGRectMake(progressX, progressY, width, _progressHeight);
if (animated) {
[UIView animateWithDuration:_animateDuration animations:^{
progressView.frame = CGRectMake(progressX, progressY, width, _progressHeight);
}];
}else {
if (_barStyle == TYPagerBarStyleHalfArcView) {
[self creatHalfArcProgressViewWithIndex:index originView:progressView];
}else {
progressView.frame = CGRectMake(progressX, progressY, width, _progressHeight);
}
}
}
}

- (void)creatHalfArcProgressViewWithIndex:(NSInteger)index originView:(UIView *)oriView {
[[oriView.layer.sublayers copy] enumerateObjectsUsingBlock:^(CALayer *layer, NSUInteger idx, BOOL * _Nonnull stop) {
[layer removeFromSuperlayer];
}];
oriView.frame = self.pagerTabBar.collectionView.frame;
oriView.backgroundColor = [UIColor clearColor];
NSInteger countOfCell = self.pagerTabBar.countOfItems;
CGFloat margin = self.cellSpacing * 1.0 / 3.0;
UIBezierPath *bezierPath = [[UIBezierPath alloc] init];
NSMutableArray *pointArray = [NSMutableArray array];
for (int i = 0; i < countOfCell + 3; i ++) {
CGFloat point_x;
CGFloat point_y;
CGRect rect;
CGPoint point;
if (i == index + 1) {
rect = [self cellFrameWithIndex:i-1];
point_x = rect.origin.x - margin ;
point_y = rect.origin.y + margin;
point = CGPointMake(point_x, point_y);
}else if (i == index +2) {
rect = [self cellFrameWithIndex:i-2];
point_x = rect.origin.x + rect.size.width + margin;
point_y = rect.origin.y + margin;
point = CGPointMake(point_x, point_y);
}else if (i == index + 3) {
rect = [self cellFrameWithIndex:i-2];
CGPoint lastPoint = [pointArray[i-1] CGPointValue];
point_x = lastPoint.x;
point_y = (rect.origin.y + rect.size.height) * 4.0 / 5.0;
point = CGPointMake(point_x, point_y);
}else if (i == countOfCell+2) {
rect = [self cellFrameWithIndex:i-3];
point_x = rect.origin.x + rect.size.width + margin;
point_y = (rect.origin.y + rect.size.height) * 4.0 / 5.0;
point = CGPointMake(point_x, point_y);
}else {
if (i <= index) {
rect = [self cellFrameWithIndex:i];
point_x = rect.origin.x - margin;
point_y = (rect.origin.y + rect.size.height) * 4.0 / 5.0;
point = CGPointMake(point_x, point_y);
}else {
rect = [self cellFrameWithIndex:i-2];
point_x = rect.origin.x - margin;
point_y = (rect.origin.y + rect.size.height) * 4.0 / 5.0;
point = CGPointMake(point_x, point_y);
}
}
[pointArray addObject:[NSValue valueWithCGPoint:point]];
if (i == 0) {
[bezierPath moveToPoint:point];
}else if (i == index + 1) {
CGPoint curPoint = CGPointMake(point.x + 5, point.y + 5);
[bezierPath addArcWithCenter:curPoint radius:5 startAngle:M_PI endAngle:M_PI * 3.0 / 2.0 clockwise:YES];
}else if (i == index + 2) {
CGPoint curPoint = CGPointMake(point.x - 5, point.y + 5);
[bezierPath addArcWithCenter:curPoint radius:5 startAngle:M_PI *3.0 / 2.0 endAngle:0 clockwise:YES];
}else {
[bezierPath addLineToPoint:point];
}
}

CGPoint lastPoint = [pointArray.lastObject CGPointValue];
if (lastPoint.x < self.pagerTabBar.collectionView.frame.size.width - self.sectionInset.left) {
CGPoint point = CGPointMake(self.pagerTabBar.collectionView.frame.size.width - self.sectionInset.left, lastPoint.y);
[bezierPath addLineToPoint:point];
}


CAShapeLayer *borderLayer = [CAShapeLayer layer];
borderLayer.lineWidth = kHalfArcProgressViewLineHeight;
borderLayer.strokeColor = self.HalfArcColor.CGColor;
borderLayer.fillColor = [UIColor clearColor].CGColor;
borderLayer.path = bezierPath.CGPath;
[oriView.layer addSublayer:borderLayer];
}
- (void)setUnderLineFrameWithfromIndex:(NSInteger)fromIndex toIndex:(NSInteger)toIndex progress:(CGFloat)progress
{
UIView *progressView = _pagerTabBar.progressView;
Expand Down Expand Up @@ -324,8 +416,11 @@ - (void)setUnderLineFrameWithfromIndex:(NSInteger)fromIndex toIndex:(NSInteger)t
progressX = (toCellFrame.origin.x+progressToEdging-(fromCellFrame.origin.x+progressFromEdging))*progress+fromCellFrame.origin.x+progressFromEdging;
width = (toCellFrame.size.width-2*progressToEdging)*progress + (fromCellFrame.size.width-2*progressFromEdging)*(1-progress);
}

progressView.frame = CGRectMake(progressX,progressY, width, _progressHeight);
if (_barStyle == TYPagerBarStyleHalfArcView) {

}else {
progressView.frame = CGRectMake(progressX,progressY, width, _progressHeight);
}
}

- (void)layoutSubViews {
Expand Down