Skip to content

Commit

Permalink
增加页面切换之后的代理,方便处理逻辑
Browse files Browse the repository at this point in the history
  • Loading branch information
lsp1286 committed Feb 6, 2018
1 parent 0c2f12d commit 95ea1ff
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 15 deletions.
Binary file not shown.
2 changes: 2 additions & 0 deletions PageViewDemo/PageViewDemo/PageView/LSPContentView.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@

- (void)contentViewEndScrollWithContentView:(LSPContentView *)contentView;

- (void)scrollViewDidEndDeceleratingWithIndex:(NSInteger)index;

@end

@interface LSPContentView : UIView
Expand Down
4 changes: 4 additions & 0 deletions PageViewDemo/PageViewDemo/PageView/LSPContentView.m
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,10 @@ - (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
if ([self.delegate respondsToSelector:@selector(contentViewEndScrollWithContentView:)]) {
[self.delegate contentViewEndScrollWithContentView:self];
}

if ([self.delegate respondsToSelector:@selector(scrollViewDidEndDeceleratingWithIndex:)]) {
[self.delegate scrollViewDidEndDeceleratingWithIndex:(NSInteger)(currentOffsetX / scrollViewW)];
}
}

- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate{
Expand Down
14 changes: 13 additions & 1 deletion PageViewDemo/PageViewDemo/PageView/LSPPageView.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,19 @@
#import "LSPTitleStyle.h"
#import "LSPTitleView.h"
#import "LSPContentView.h"

@class LSPPageView;
@protocol LSPPageViewDelegate <NSObject>

//页面切换完成之后
- (void)pageViewScollEndView:(LSPPageView *)pageView WithIndex:(NSInteger)index;

@end

@interface LSPPageView : UIView

/**
直接在需要PageView的控制器中,一句代码实例化(调用此方法),如需更改TitleView和ContentView的Frame在XTitleStyle.m中重新设置Frame即可
直接在需要PageView的控制器中,一句代码实例化(调用此方法),如需更改TitleView的样式在LSPTitleStyle.m中重新设置即可
@param frame PageView的Frame
@param titles 标题数组
Expand All @@ -24,4 +33,7 @@
*/
- (LSPPageView *)initWithFrame:(CGRect)frame titles:(NSArray <NSString *>*)titles style:(LSPTitleStyle *)style childVcs:(NSArray <UIViewController *>*)childVcs parentVc:(UIViewController *)parentVc;


@property(nonatomic, weak) id <LSPPageViewDelegate> delegate;

@end
10 changes: 10 additions & 0 deletions PageViewDemo/PageViewDemo/PageView/LSPPageView.m
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ - (void)setupUI{
#pragma mark - XTitleViewDelegate
- (void)titleViewWithTitleView:(LSPTitleView *)titleView selectedIndex:(NSInteger)selectedIndex{
[self.contentView setCurrentIndex:selectedIndex];

if ([self.delegate respondsToSelector:@selector(pageViewScollEndView:WithIndex:)]) {
[self.delegate pageViewScollEndView:self WithIndex:selectedIndex];
}
}

#pragma mark - XContentViewDelegate
Expand All @@ -86,5 +90,11 @@ - (void)contentViewWith:(LSPContentView *)contentView progress:(CGFloat)progress
- (void)contentViewEndScrollWithContentView:(LSPContentView *)contentView{
[self.titleView contentViewDidEndScroll];
}
- (void)scrollViewDidEndDeceleratingWithIndex:(NSInteger)index
{
if ([self.delegate respondsToSelector:@selector(pageViewScollEndView:WithIndex:)]) {
[self.delegate pageViewScollEndView:self WithIndex:index];
}
}

@end
21 changes: 7 additions & 14 deletions PageViewDemo/PageViewDemo/ViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#import "ViewController.h"

#import "LSPPageView.h"
@interface ViewController ()
@interface ViewController ()<LSPPageViewDelegate>

@end

Expand All @@ -26,7 +26,7 @@ - (void)viewDidLoad {
for (int i = 0; i < 15; i++) {
[testArray addObject:[NSString stringWithFormat:@"Test%d",i]];
}
// NSArray *titles = @[@"BTC0",@"ETH",@"BNB",@"TRX",@"BTC",@"ETH",@"BNB",@"TRX"];

NSMutableArray *childVcArray = [NSMutableArray array];
for (int i = 0; i < testArray.count; i++) {
UIViewController *vc = [[UIViewController alloc] init];
Expand All @@ -38,22 +38,15 @@ - (void)viewDidLoad {
[childVcArray addObject:vc];
}
LSPPageView *pageView = [[LSPPageView alloc] initWithFrame:CGRectMake(0, 64, self.view.bounds.size.width, self.view.bounds.size.height - 64) titles:testArray.mutableCopy style:nil childVcs:childVcArray.mutableCopy parentVc:self];
pageView.delegate = self;
pageView.backgroundColor = [UIColor whiteColor];
[self.view addSubview:pageView];

}

- (void)testSegment{

}

- (void)change:(UISegmentedControl *)seg{

}

- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
#pragma mark - LSPPageViewDelegate
- (void)pageViewScollEndView:(LSPPageView *)pageView WithIndex:(NSInteger)index
{
NSLog(@"%zd",index);
}


Expand Down

0 comments on commit 95ea1ff

Please sign in to comment.