• Stars
    star
    1,375
  • Rank 34,198 (Top 0.7 %)
  • Language
    Objective-C
  • License
    MIT License
  • Created over 8 years ago
  • Updated over 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

page scroll view and controller,simple,high custom,and have many tabBar styles,,support Objective-C and swift

TYPagerController v2.0

TYPagerController 简单,强大,高度定制,页面控制器,水平滚动内容和标题栏,包含多种barStyle。
TYPagerController v2.0 重构优化代码,分离出TYPagerViewLayout布局类,添加更多功能,更加强大,稳定,已经在项目中使用
如果还想使用以前的版本可以查看分支v1.0.6 和 pod 'TYPagerController', '~> 1.0.6'

  • TYPagerViewLayout 水平滚动页面的layout类,只需要initWithScrollView:即可实现水平滚动页面.
  • TYPagerView 包含TYPagerViewLayout的水平滚动页面View
  • TYPagerController 包含TYPagerViewLayout的水平滚动页面Controller。
  • TYTabPagerBar Pager的标题 tabBar
  • TYTabPagerView 包含TabBar的TYPagerView
  • TYTabPagerController 包含TabBar的TYPagerController

注意:获取数据后必须调用reloadData.
更详细的使用请看LovePlayNews项目

CocoaPods

pod 'TYPagerController'

Requirements

  • Xcode 7 or higher
  • iOS 7.0 or higher
  • ARC

ScreenShot

TYPagerBarStyle

New TYPagerBarStyleProgressElasticView
image

1 TYPagerBarStyleProgressBounceView
image

2 TYPagerBarStyleProgressView
image

3 TYPagerBarStyleCoverView
image image

4 TYPagerBarStyleNoneView
image

API

Class

  • TYPagerViewLayout
@interface TYPagerViewLayout<__covariant ItemType> : NSObject

@property (nonatomic, weak, nullable) id<TYPagerViewLayoutDataSource> dataSource;
@property (nonatomic, weak, nullable) id<TYPagerViewLayoutDelegate> delegate;

// strong,will control the delegate,don't set delegate on other place.
@property (nonatomic, strong, readonly) UIScrollView *scrollView;
// if viewcontroller's automaticallyAdjustsScrollViewInsets YES ,will cause frame problems, you can set YES, default YES
@property (nonatomic, assign) BOOL adjustScrollViewInset;

@property (nonatomic, assign, readonly) NSInteger countOfPagerItems;
@property (nonatomic, assign, readonly) NSInteger curIndex;// default -1

@property (nonatomic, strong, readonly) NSCache<NSNumber *,ItemType> *memoryCache;; // will cache pagerView,you can set countLimit
@property (nonatomic, assign) BOOL autoMemoryCache; // default YES

@property (nonatomic, assign) NSInteger prefetchItemCount;// preload left and right item's count , default 0

@property (nonatomic, assign, readonly) NSRange prefetchRange;
@property (nonatomic, assign, readonly) NSRange visibleRange;

@property (nonatomic, strong, nullable, readonly) NSArray<NSNumber *> * visibleIndexs;
@property (nonatomic, strong, nullable, readonly) NSArray<ItemType> * visibleItems;

// default YES, if NO,will not call delegate transitionFromIndex:toIndex:progress:,but will call transitionFromIndex:toIndex:
@property (nonatomic, assign) BOOL progressAnimateEnabel;

// default NO, when scroll visible range change will add item.If YES add item only when scroll animate end, suggest set prefetchItemCount 1 or more
@property (nonatomic, assign) BOOL addVisibleItemOnlyWhenScrollAnimatedEnd;

// default 0.5,when scroll progress percent will change index, only progressAnimateEnabel is NO or don't implement delegate transitionFromIndex: toIndex: progress:
@property (nonatomic, assign) CGFloat changeIndexWhenScrollProgress;
  • TYPagerView
@interface TYPagerView : UIView

@property (nonatomic, weak, nullable) id<TYPagerViewDataSource> dataSource;
@property (nonatomic, weak, nullable) id<TYPagerViewDelegate> delegate;
// pagerView's layout,don't set layout's dataSource to other
@property (nonatomic, strong, readonly) TYPagerViewLayout<UIView *> *layout;
@property (nonatomic, strong, readonly) UIScrollView *scrollView;

@property (nonatomic, assign, readonly) NSInteger countOfPagerViews;
@property (nonatomic, assign, readonly) NSInteger curIndex;// default -1

@property (nonatomic, assign, nullable, readonly) NSArray<UIView *> *visibleViews;

@property (nonatomic, assign) UIEdgeInsets contentInset;

//if not visible, prefecth, cache view at index, return nil
- (UIView *_Nullable)viewForIndex:(NSInteger)index;

// register && dequeue's usage like tableView
- (void)registerClass:(Class)Class forViewWithReuseIdentifier:(NSString *)identifier;
- (void)registerNib:(UINib *)nib forViewWithReuseIdentifier:(NSString *)identifier;
- (UIView *)dequeueReusableViewWithReuseIdentifier:(NSString *)identifier forIndex:(NSInteger)index;

// scroll to index
- (void)scrollToViewAtIndex:(NSInteger)index animate:(BOOL)animate;

// update data and layout,but don't reset propertys(curIndex,visibleDatas,prefechDatas)
- (void)updateData;

// reload data and reset propertys
- (void)reloadData;
@protocol TYTabPagerControllerDelegate <TYPagerControllerDelegate>

// configre collectionview cell
- (void)pagerController:(TYTabPagerController *)pagerController configreCell:(UICollectionViewCell *)cell forItemTitle:(NSString *)title atIndexPath:(NSIndexPath *)indexPath;

// transition frome cell to cell with animated
- (void)pagerController:(TYTabPagerController *)pagerController transitionFromeCell:(UICollectionViewCell *)fromCell toCell:(UICollectionViewCell *)toCell animated:(BOOL)animated;

// transition frome cell to cell with progress
- (void)pagerController:(TYTabPagerController *)pagerController transitionFromeCell:(UICollectionViewCell *)fromCell toCell:(UICollectionViewCell *)toCell progress:(CGFloat)progress;

@end
  • TYPagerController
@interface TYPagerController : UIViewController

@property (nonatomic, weak, nullable) id<TYPagerControllerDataSource> dataSource;
@property (nonatomic, weak, nullable) id<TYPagerControllerDelegate>   delegate;
// pagerController's layout,don't set layout's dataSource to other
@property (nonatomic, strong, readonly) TYPagerViewLayout<UIViewController *> *layout;
@property (nonatomic, weak, readonly) UIScrollView *scrollView;

@property (nonatomic, assign, readonly) NSInteger countOfControllers;
@property (nonatomic, assign, readonly) NSInteger curIndex;// default -1

@property (nonatomic, strong, nullable, readonly) NSArray<UIViewController *> *visibleControllers;

@property (nonatomic, assign) UIEdgeInsets contentInset;

//if not visible, prefecth, cache view at index, return nil
- (UIViewController *_Nullable)controllerForIndex:(NSInteger)index;

// register && dequeue's usage like tableView
- (void)registerClass:(Class)Class forControllerWithReuseIdentifier:(NSString *)identifier;
- (void)registerNib:(UINib *)nib forControllerWithReuseIdentifier:(NSString *)identifier;
- (UIViewController *)dequeueReusableControllerWithReuseIdentifier:(NSString *)identifier forIndex:(NSInteger)index;

// scroll to index
- (void)scrollToControllerAtIndex:(NSInteger)index animate:(BOOL)animate;

//  update data and layout,but don't reset propertys(curIndex,visibleDatas,prefechDatas)
- (void)updateData;

// reload data and reset propertys
- (void)reloadData;

##Usage Demo

  • TYTabPagerView
- (void)addTabPagerView {
    TYTabPagerView *pagerView = [[TYTabPagerView alloc]init];
    pagerView.tabBar.layout.barStyle = TYPagerBarStyleCoverView;
    pagerView.tabBar.progressView.backgroundColor = [UIColor lightGrayColor];
    pagerView.dataSource = self;
    pagerView.delegate = self;
    [self.view addSubview:pagerView];
    _pagerView = pagerView;
}

#pragma mark - TYTabPagerViewDataSource

- (NSInteger)numberOfViewsInTabPagerView {
    return _datas.count;
}

- (UIView *)tabPagerView:(TYTabPagerView *)tabPagerView viewForIndex:(NSInteger)index prefetching:(BOOL)prefetching {
    UIView *view = [[UIView alloc]initWithFrame:[tabPagerView.layout frameForItemAtIndex:index]];
    view.backgroundColor = [UIColor colorWithRed:arc4random()%255/255.0 green:arc4random()%255/255.0 blue:arc4random()%255/255.0 alpha:arc4random()%255/255.0];
    //NSLog(@"viewForIndex:%ld prefetching:%d",index,prefetching);
    return view;
}

- (NSString *)tabPagerView:(TYTabPagerView *)tabPagerView titleForIndex:(NSInteger)index {
    NSString *title = _datas[index];
    return title;
}
  • TYTabPagerController
@interface TabPagerControllerDemoController : TYTabPagerController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.title = @"TabPagerControllerDemoController";
    self.tabBar.layout.barStyle = TYPagerBarStyleProgressView;
    self.dataSource = self;
    self.delegate = self;
    
    [self loadData];
}

- (void)loadData {
    _datas = [datas copy];
    // must call reloadData
    [self reloadData];
}

#pragma mark - TYTabPagerControllerDataSource

- (NSInteger)numberOfControllersInTabPagerController {
    return _datas.count;
}

- (UIViewController *)tabPagerController:(TYTabPagerController *)tabPagerController controllerForIndex:(NSInteger)index prefetching:(BOOL)prefetching {
    if (index%3 == 0) {
        CustomViewController *VC = [[CustomViewController alloc]init];
        VC.text = [@(index) stringValue];
        return VC;
    }else if (index%3 == 1) {
        ListViewController *VC = [[ListViewController alloc]init];
        VC.text = [@(index) stringValue];
        return VC;
    }else {
        CollectionViewController *VC = [[CollectionViewController alloc]init];
        VC.text = [@(index) stringValue];
        return VC;
    }
}

- (NSString *)tabPagerController:(TYTabPagerController *)tabPagerController titleForIndex:(NSInteger)index {
    NSString *title = _datas[index];
    return title;
}

更多的使用方法 请查看 demo。

Contact

如果你发现bug,please pull reqeust me
如果你有更好的改进,please pull reqeust me

More Repositories

1

TYAttributedLabel

TYAttributedLabel 简单,强大的属性文本控件(无需了解CoreText),支持图文混排显示,支持添加链接,image和UIView控件,支持自定义排版显示
Objective-C
2,890
star
2

TYCyclePagerView

a simple and usefull cycle pager view ,and auto scroll banner view(轮播图) ,include pageControl for iOS,support Objective-C and swift
Objective-C
1,755
star
3

DOPDropDownMenu-Enhanced

DOPDropDownMenu 添加双列表 优化版 新增图片支持(double tableView, The optimization version ,new add image,detailText)
Objective-C
1,748
star
4

TYAlertController

Powerful, Easy to use alert view or popup view on controller and window, support blur effects,custom view and animation,for objective-c,support iphone, ipad
Objective-C
1,312
star
5

LovePlayNews

LovePlayNews精仿爱玩iOS app,使用AsyncDisplayKit提高UI流畅性,项目结构及代码清晰明了
Objective-C
668
star
6

TYDownloadManager

Download file manager wrapped NSURLSessionDataTask and NSURLSessionDownloadTask,provide progress update and status change.
Objective-C
412
star
7

TYWaterWaveView

水波浪圆形进度控件,采用 CAShapeLayer,CADisplayLink 波浪动画,简单,流畅
Objective-C
398
star
8

TReaderBook

图文混排阅读器
Objective-C
276
star
9

TYLaunchAnimation

launching image or view Animation,UIView Category,easy to use.(启动图动画,带广告, 直接使用,支持自定义view,自定义动画)
Objective-C
271
star
10

KnowingLife

基于天气,查询,团购,新闻类查询应用,自己自学ios,写的第一个ios项目,也是面试作品,好久没用了,放着可惜,拿来给大家分享,希望给想写个项目,又无处着手的新人帮助,新手作品
Objective-C
140
star
11

TYText

text asynchronous rendering by TextKit for iOS
Objective-C
135
star
12

Prism

Application Performance Management & Monitoring for iOS (APM)
Objective-C
71
star
13

TYSwizzleDemo

method swizzling easy to use ,C Function and NSObject Categary
Objective-C
13
star
14

TYHttpManager

网络请求管理库,基于对AFNetwork的封装
Objective-C
13
star
15

TYDecorationSectionLayout

custom collectionView sections background view (decoration view)
Objective-C
11
star
16

WeiboDemo

Weibo demo using asynchronous rendering by TYText
Objective-C
10
star
17

TYJSONModel

A fast conversion between JSON and Model
Objective-C
7
star
18

BulletAnalyzer

斗鱼弹幕分析工具, 语义近似度合并, CG/CA图表数据绘制, Socket链接
Objective-C
5
star
19

TYPopupController

TYPopupController is presenting view controller or view as popups of other view controller
Objective-C
5
star
20

TYRefresh

a simple way to use pull-to-refresh (上下拉刷新),easy way to customize loading animation(自定义加载动画).
Objective-C
3
star
21

TYBarrageManager

barrage manager view (弹幕)
Objective-C
1
star
22

12207480.github.io

HTML
1
star
23

iOS-Txt-Core

A simple demo for UIPageViewController.
Objective-C
1
star
24

xinWeibo-demo

sina weibo demo 新浪微博 demo
Objective-C
1
star