BBACyclePagerView.h
4.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
//
// BBACyclePagerView.h
// CyclePagerView
//
// Created by xuxiaonan on 2017/9/28.
// Copyright © 2017年 xuxiaonan. All rights reserved.
//
#import <UIKit/UIKit.h>
#import "BBACyclePagerTransformLayout.h"
NS_ASSUME_NONNULL_BEGIN
// pagerView scrolling direction
typedef NS_ENUM(NSUInteger, BBAPagerScrollDirection) {
BBAPagerScrollDirectionLeft,
BBAPagerScrollDirectionRight,
};
@class BBACyclePagerView;
@protocol BBACyclePagerViewDataSource <NSObject>
- (NSInteger)numberOfItemsInPagerView:(BBACyclePagerView *)pageView;
- (__kindof UICollectionViewCell *)pagerView:(BBACyclePagerView *)pagerView cellForItemAtIndex:(NSInteger)index;
/**
return pagerView layout,and cache layout
*/
- (BBACyclePagerViewLayout *)layoutForPagerView:(BBACyclePagerView *)pageView;
@end
@protocol BBACyclePagerViewDelegate <NSObject>
@optional
/**
pagerView did scroll to new index page
*/
- (void)pagerView:(BBACyclePagerView *)pageView didScrollFromIndex:(NSInteger)fromIndex toIndex:(NSInteger)toIndex;
/**
pagerView did selected item cell
*/
- (void)pagerView:(BBACyclePagerView *)pageView didSelectedItemCell:(__kindof UICollectionViewCell *)cell atIndex:(NSInteger)index;
// custom layout
- (void)pagerView:(BBACyclePagerView *)pageView initializeTransformAttributes:(UICollectionViewLayoutAttributes *)attributes;
- (void)pagerView:(BBACyclePagerView *)pageView applyTransformToAttributes:(UICollectionViewLayoutAttributes *)attributes;
// scrollViewDelegate
- (void)pagerViewDidScroll:(BBACyclePagerView *)pageView;
- (void)pagerViewWillBeginDragging:(BBACyclePagerView *)pageView;
- (void)pagerViewDidEndDragging:(BBACyclePagerView *)pageView willDecelerate:(BOOL)decelerate;
- (void)pagerViewWillBeginDecelerating:(BBACyclePagerView *)pageView;
- (void)pagerViewDidEndDecelerating:(BBACyclePagerView *)pageView;
- (void)pagerViewWillBeginScrollingAnimation:(BBACyclePagerView *)pageView;
- (void)pagerViewDidEndScrollingAnimation:(BBACyclePagerView *)pageView;
@end
@interface BBACyclePagerView : UIView
// will be automatically resized to track the size of the pagerView
@property (nonatomic, strong, nullable) UIView *backgroundView;
@property (nonatomic, weak, nullable) id<BBACyclePagerViewDataSource> dataSource;
@property (nonatomic, weak, nullable) id<BBACyclePagerViewDelegate> delegate;
// pager view layout
@property (nonatomic, strong, readonly) BBACyclePagerViewLayout *layout;
/**
is infinite cycle pageview
*/
@property (nonatomic, assign) BOOL isInfiniteLoop;
/**
pagerView automatic scroll time interval, default 0,disable automatic
*/
@property (nonatomic, assign) CGFloat autoScrollInterval;
/**
current page index
*/
@property (nonatomic, assign, readonly) NSInteger curIndex;
// scrollView property
@property (nonatomic, assign, readonly) CGPoint contentOffset;
@property (nonatomic, assign, readonly) BOOL tracking;
@property (nonatomic, assign, readonly) BOOL dragging;
@property (nonatomic, assign, readonly) BOOL decelerating;
/**
set scroll not like page
*/
@property (nonatomic, assign) BOOL scrollNormal;
/**
reload data, !!important!!: will clear layout and call delegate layoutForPagerView
*/
- (void)reloadData;
/**
update data is reload data, but not clear layuot
*/
- (void)updateData;
/**
if you only want update layout
*/
- (void)setNeedUpdateLayout;
/**
will set layout nil and call delegate->layoutForPagerView
*/
- (void)setNeedClearLayout;
/**
current index cell in pagerView
*/
- (__kindof UICollectionViewCell * _Nullable)curIndexCell;
/**
visible cells in pageView
*/
- (NSArray<__kindof UICollectionViewCell *> *_Nullable)visibleCells;
/**
visible pageView indexs, maybe repeat index
*/
- (NSArray *)visibleIndexs;
/**
scroll to item at index
*/
- (void)scrollToItemAtIndex:(NSInteger)index animate:(BOOL)animate;
/**
scroll to next or pre item
*/
- (void)scrollToNearlyIndexAtDirection:(BBAPagerScrollDirection)direction animate:(BOOL)animate;
/**
register pager view cell with class
*/
- (void)registerClass:(Class)Class forCellWithReuseIdentifier:(NSString *)identifier;
/**
register pager view cell with nib
*/
- (void)registerNib:(UINib *)nib forCellWithReuseIdentifier:(NSString *)identifier;
/**
dequeue reusable cell for pagerView
*/
- (__kindof UICollectionViewCell *)dequeueReusableCellWithReuseIdentifier:(NSString *)identifier forIndex:(NSInteger)index;
@end
NS_ASSUME_NONNULL_END