Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

优化 可滑动的小标签 #11

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
20 changes: 7 additions & 13 deletions ZTPageController/Demo/Class/MenuView.m
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ - (void)loadWithScollviewAndBtnWithTitles:(NSArray *)titles {
MenuScrollView.showsVerticalScrollIndicator = NO;
MenuScrollView.showsHorizontalScrollIndicator = NO;
MenuScrollView.backgroundColor = [UIColor whiteColor];
MenuScrollView.delegate = self;
self.MenuScrollView= MenuScrollView;
[self addSubview:self.MenuScrollView];
//btn创建
Expand Down Expand Up @@ -236,24 +235,19 @@ - (void)MoveCodeWithIndex:(int )index {
if (index > count-1) return;

if ( self.MenuScrollView.contentOffset.x + btn.x > self.centerX ) {

[self.MenuScrollView setContentOffset:CGPointMake(contenoffsetX + distance + btn.width, 0) animated:YES];
float moveX = contenoffsetX + distance + btn.width;
float contentOfSum = self.MenuScrollView.contentSize.width - self.MenuScrollView.width;
if (moveX > contentOfSum) {
[self.MenuScrollView setContentOffset:CGPointMake(contentOfSum, 0) animated:YES];
}else{
[self.MenuScrollView setContentOffset:CGPointMake(contenoffsetX + distance + btn.width/2, 0) animated:YES];
}
}else{

[self.MenuScrollView setContentOffset:CGPointMake(0 , 0) animated:YES];
}
}

- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
if (scrollView.contentOffset.x <= 0) {

[scrollView setContentOffset:CGPointMake(0 , 0)];
}else if(scrollView.contentOffset.x + self.width >= scrollView.contentSize.width){

[scrollView setContentOffset:CGPointMake(scrollView.contentSize.width - self.width, 0)];
}
}

- (void)selectWithIndex:(int)index AndOtherIndex:(int)tag {
self.selectedBtn = self.MenuScrollView.subviews[index];
MenuViewBtn *otherbtn = self.MenuScrollView.subviews[tag];
Expand Down