Skip to content

Commit

Permalink
[Releases 1.6.5] 滚动样式下 titleTextZoom 属性支持指示器下划线及遮盖样式下的滚动
Browse files Browse the repository at this point in the history
  • Loading branch information
kingsic committed Jul 20, 2019
1 parent ca68841 commit 6950fb0
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 13 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ SGPageContentCollectionView(内部由 UICollectionView 实现)


## Installation
* 1、CocoaPods 导入 pod 'SGPagingView', '~> 1.6.3'
* 1、CocoaPods 导入 pod 'SGPagingView', '~> 1.6.5'
* 2、下载、拖拽 “SGPagingView” 文件夹到工程中


Expand Down Expand Up @@ -176,6 +176,8 @@ b. 实现 SGPageContentScrollView 的 pageContentScrollView:index:代理方法

* 2019-07-17 :v1.6.3 修复设置图片样式下图片布局问题以及对内部代码的优化处理

* 2019-07-20 :v1.6.5 滚动样式下 titleTextZoom 属性支持指示器下划线及遮盖样式下的滚动


## License
SGPagingView is released under the MIT license. See [LICENSE](https://github.com/kingsic/SGPagingView/blob/master/LICENSE) for details.
2 changes: 1 addition & 1 deletion SGPagingView.podspec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Pod::Spec.new do |s|
s.name = 'SGPagingView'
s.version = '1.6.3'
s.version = '1.6.5'
s.summary = 'A powerful and easy to use segment control'
s.homepage = 'https://github.com/kingsic/SGPagingView'
s.license = 'MIT'
Expand Down
61 changes: 53 additions & 8 deletions SGPagingView/SGPageTitle/SGPageTitleView.m
Original file line number Diff line number Diff line change
Expand Up @@ -382,8 +382,30 @@ - (void)P_changeSelectedButton:(UIButton *)button {
UIButton *btn = obj;
btn.transform = CGAffineTransformIdentity;
}];

// 1.记录按钮缩放前的宽度
CGFloat zoomFrontBtnWidth = button.SG_width;

/// 处理按钮缩放
CGFloat afterZoomRatio = 1 + self.configure.titleTextZoomRatio;
button.transform = CGAffineTransformMakeScale(afterZoomRatio, afterZoomRatio);

// 2.记录按钮缩放后的宽度
CGFloat zoomAfterBtnWidth = button.SG_width;
// 缩放后与缩放前之间的差值
CGFloat diffForntAfter = zoomAfterBtnWidth - zoomFrontBtnWidth;

/// 处理指示器
if (self.configure.indicatorAdditionalWidth >= diffForntAfter) {
self.configure.indicatorAdditionalWidth = diffForntAfter;
}
CGSize tempSize = [self P_sizeWithString:button.currentTitle font:self.configure.titleFont];
CGFloat tempIndicatorWidth = self.configure.indicatorAdditionalWidth + tempSize.width + self.configure.titleTextZoomRatio * tempSize.width;
if (tempIndicatorWidth > button.SG_width) {
tempIndicatorWidth = button.SG_width - self.configure.titleTextZoomRatio * tempSize.width;
}
self.indicatorView.SG_width = tempIndicatorWidth;
self.indicatorView.SG_centerX = button.SG_centerX;
}

// 此处作用:避免滚动过程中点击标题手指不离开屏幕的前提下再次滚动造成的误差(由于文字渐变效果导致未选中标题的不准确处理)
Expand Down Expand Up @@ -441,13 +463,16 @@ - (void)P_changeIndicatorWithButton:(UIButton *)button {
return;
}

CGSize tempSize = [self P_sizeWithString:button.currentTitle font:self.configure.titleFont];
CGFloat tempIndicatorWidth = self.configure.indicatorAdditionalWidth + tempSize.width;
if (tempIndicatorWidth > button.SG_width) {
tempIndicatorWidth = button.SG_width;
if (self.configure.titleTextZoom == NO) {
CGSize tempSize = [self P_sizeWithString:button.currentTitle font:self.configure.titleFont];
CGFloat tempIndicatorWidth = self.configure.indicatorAdditionalWidth + tempSize.width;
if (tempIndicatorWidth > button.SG_width) {
tempIndicatorWidth = button.SG_width;
}
self.indicatorView.SG_width = tempIndicatorWidth;
self.indicatorView.SG_centerX = button.SG_centerX;
}
self.indicatorView.SG_width = tempIndicatorWidth;
self.indicatorView.SG_centerX = button.SG_centerX;

}];
}

Expand Down Expand Up @@ -845,9 +870,29 @@ - (void)P_indicatorScrollStyleDefaultWithProgress:(CGFloat)progress originalBtn:
}


/// 处理指示器下划线、遮盖样式
/// 处理指示器下划线、遮盖样式 (1.6.5 版本起标题文字缩放属性与指示器下划线、遮盖样式已兼容)
if (self.configure.titleTextZoom && self.configure.showIndicator) {
NSLog(@"温馨提示:[SGPageTitleView 滚动样式下] 标题文字缩放属性与指示器下划线及遮盖样式不兼容,但固定及动态样式兼容");
// NSLog(@"温馨提示:[SGPageTitleView 滚动样式下] 标题文字缩放属性与指示器下划线及遮盖样式不兼容,但固定及动态样式兼容");
CGFloat originalBtnTextWidth = [self P_sizeWithString:originalBtn.currentTitle font:self.configure.titleFont].width;
CGFloat targetBtnTextWidth = [self P_sizeWithString:targetBtn.currentTitle font:self.configure.titleFont].width;
// 文字距离差
CGFloat diffText = targetBtnTextWidth - originalBtnTextWidth;
// 中心点距离差
CGFloat distanceCenter = targetBtn.SG_centerX - originalBtn.SG_centerX;
CGFloat offsetCX = 0.0;

CGFloat tempIndicatorWidth = self.configure.indicatorAdditionalWidth + targetBtnTextWidth + self.configure.titleTextZoomRatio * targetBtnTextWidth;
if (tempIndicatorWidth >= targetBtn.SG_width) {
offsetCX = distanceCenter * progress;
_indicatorView.SG_centerX = originalBtn.SG_centerX + offsetCX;
CGFloat tempIndicatorW = originalBtnTextWidth + diffText * progress;
_indicatorView.SG_width = targetBtn.SG_width - self.configure.titleTextZoomRatio * tempIndicatorW;
} else {
offsetCX = distanceCenter * progress;
_indicatorView.SG_centerX = originalBtn.SG_centerX + offsetCX;
CGFloat tempIndicatorW = originalBtnTextWidth + diffText * progress;
_indicatorView.SG_width = tempIndicatorW + self.configure.titleTextZoomRatio * tempIndicatorW + self.configure.indicatorAdditionalWidth;
}
return;
}

Expand Down
2 changes: 1 addition & 1 deletion SGPagingView/SGPagingView.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//
// SGPagingView.h
// Version 1.6.3
// Version 1.6.5
// GitHub:https://github.com/kingsic/SGPagingView
//
// Created by kingsic on 2016/10/6.
Expand Down
4 changes: 2 additions & 2 deletions SGPagingViewExample/MainVC/DefaultZoomVC.m
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@ - (void)setupPageView {

NSArray *titleArr = @[@"精选", @"电影", @"电视剧", @"综艺", @"NBA", @"娱乐", @"动漫", @"演唱会", @"VIP会员"];
SGPageTitleViewConfigure *configure = [SGPageTitleViewConfigure pageTitleViewConfigure];
configure.showIndicator = NO;
// configure.showIndicator = NO;
configure.titleTextZoom = YES;
configure.titleTextZoomRatio = 0.5;
configure.titleAdditionalWidth = 30;
configure.titleGradientEffect = YES;

/// pageTitleView
self.pageTitleView = [SGPageTitleView pageTitleViewWithFrame:CGRectMake(0, pageTitleViewY, self.view.frame.size.width, 44) delegate:self titleNames:titleArr configure:configure];
[self.view addSubview:_pageTitleView];
Expand Down

0 comments on commit 6950fb0

Please sign in to comment.