├── License
├── README.md
├── README_EN.md
├── ScreenShots
├── SwipeTableViewStruct1.png
├── SwipeTableViewStruct2.png
├── logo.png
├── screenshot1.gif
├── screenshot2.gif
└── screenshot3.gif
├── SwipeTableView.podspec
├── SwipeTableView.xcodeproj
├── project.pbxproj
├── project.xcworkspace
│ ├── contents.xcworkspacedata
│ └── xcuserdata
│ │ └── roylee.xcuserdatad
│ │ └── UserInterfaceState.xcuserstate
└── xcuserdata
│ └── roylee.xcuserdatad
│ ├── xcdebugger
│ └── Breakpoints_v2.xcbkptlist
│ └── xcschemes
│ ├── SwipeTableView.xcscheme
│ └── xcschememanagement.plist
├── SwipeTableView
├── AppDelegate.h
├── AppDelegate.m
├── Assets.xcassets
│ └── AppIcon.appiconset
│ │ └── Contents.json
├── Base.lproj
│ ├── LaunchScreen.storyboard
│ └── Main.storyboard
├── Info.plist
├── SwipeTableView
│ ├── STCollectionView.h
│ ├── STCollectionView.m
│ ├── STHeaderView.h
│ ├── STHeaderView.m
│ ├── SwipeTableView.h
│ ├── SwipeTableView.m
│ ├── UIView+STFrame.h
│ └── UIView+STFrame.m
├── SwipeTableViewDemo
│ ├── STController
│ │ ├── STImageController.h
│ │ ├── STImageController.m
│ │ ├── STListController.h
│ │ ├── STListController.m
│ │ ├── STViewController.h
│ │ └── STViewController.m
│ ├── STRefresh
│ │ ├── STRefresh.h
│ │ ├── STRefreshHeader.h
│ │ ├── STRefreshHeader.m
│ │ ├── UIScrollView+STRefresh.h
│ │ ├── UIScrollView+STRefresh.m
│ │ └── github.png
│ ├── STTransition
│ │ ├── STTransitions.h
│ │ └── STTransitions.m
│ ├── STView
│ │ ├── CustomCollectionView.h
│ │ ├── CustomCollectionView.m
│ │ ├── CustomSegmentControl.h
│ │ ├── CustomSegmentControl.m
│ │ ├── CustomTableView.h
│ │ └── CustomTableView.m
│ └── onepiece_kiudai.png
└── main.m
└── SwipeTableViewTests
├── Info.plist
└── SwipeTableViewTests.m
/License:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2016 Roy lee.
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
23 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | 
2 |
3 | [](http://cocoapods.org/pods/SwipeTableView)
4 | 
5 | [](https://github.com/Roylee-ML/SwipeTableView/blob/master/License)
6 |
7 | 功能类似半糖首页菜单与QQ音乐歌曲列表页面。即支持UITableview的上下滚动,同时也支持不同列表之间的滑动切换。同时可以设置顶部header view与列表切换功能bar,使用方式类似于原生UITableview的tableHeaderView的方式。 [`Engilish→`](https://github.com/Roylee-ML/SwipeTableView/blob/master/README_EN.md)
8 |
9 | ⚠️**注意**: 由于该组件的实现原理并不是十分安全可靠,该组件已经停止维护。如有相同需求,请移步到 [HBHybridCollectionView](https://github.com/Ban-Tang/HBHybridCollectionView) 或者类似的组件。HBHybridCollectionView 更稳定,接入更灵活,目前知乎个人页的底层组件使用的是相同的代码。
10 | ****
11 |
12 | # 预览
13 |
14 |
15 |
16 |
17 |
18 | # 使用 Cocoapods 导入
19 | SwipeTableView is available on [CocoaPods](http://cocoapods.org). Add the following to your Podfile:
20 |
21 | ```ruby
22 | pod 'SwipeTableView'
23 | ```
24 |
25 |
26 | # 目录
27 | 1. [实现原理](https://github.com/Roylee-ML/SwipeTableView/blob/master/README.md#实现的原理)
28 | 2. [基本用法](https://github.com/Roylee-ML/SwipeTableView/blob/master/README.md#怎样使用使用方式类似uitableview)
29 | 3. [下拉刷新](https://github.com/Roylee-ML/SwipeTableView/blob/master/README.md#如何支持下拉刷新)
30 | 4. [混合模式](https://github.com/Roylee-ML/SwipeTableView/blob/master/README.md#混合模式uitableview--uicollectionview--uiscrollview)
31 | 5. [示例代码](https://github.com/Roylee-ML/SwipeTableView/blob/master/README.md#示例代码)
32 | 6. [Demo介绍](https://github.com/Roylee-ML/SwipeTableView/blob/master/README.md#使用的详细用法在swipetableviewdemo文件夹中提供了五种示例)
33 |
34 |
35 |
36 | ## 实现的原理
37 | >为了兼容下拉刷新,采用了两种实现方式,但基本构造都是一样的
38 |
39 | ### Mode 1
40 |
41 | 
42 |
43 | 1. 使用`UICollectionView`作为item的载体,实现左右滑动的功能。
44 |
45 | 2. 在支持左右滑动之后,最关键的问题就是是滑动后相邻item的对齐问题。
46 | >为实现前后item对齐,需要在itemView重用的时候,比较前后两个itemView的contentOffset,然后设置后一个itemView的contentOffset与前一个相同。这样就实现了左右滑动后前后itemView的offset是对齐的。
47 |
48 | 3. 由于多个item共用一个header与bar,所以,header与bar必须是根视图的子视图,即与CollectionView一样是`SwipeTableView`的子视图,并且在CollectionView的图层之上。
49 | >headr & bar的滚动与悬停实现是,对当前的itemView的contentOffset进行KVO。然后在当前itemView的contentOffset发生变化时,去改变header与bar的Y坐标值。
50 |
51 | 4. 顶部header & bar在图层的最顶部,所以每个itemView的顶部需要做出一个留白来作为header & bar的显示空间。在`Mode 1`中,采用修改`UIScrollView`的contentInsets的top值来留出顶部留白。
52 |
53 | 5. 由于header在图层的最顶部,所以要实现滑动header的同时使当前itemView跟随滚动,需要根据header的frame的变化回调给当前的itemView来改变contentOffset,同时也要具有ScrollView的弹性等效果。
54 | >这里采用`UIKit Dynamic`物理动画引擎自定义`STHeaderView`实现自定义`UIScrollView`效果解决上述问题 [`参考文章`](http://philcai.com/2016/03/15/%E7%94%A8UIKit-Dynamics%E6%A8%A1%E4%BB%BFUIScrollView/) [`英文博客`](http://holko.pl/2014/07/06/inertia-bouncing-rubber-banding-uikit-dynamics/)。
55 |
56 |
57 |
58 | ### Mode 2
59 |
60 | 
61 |
62 | 1. 在`Mode 2`中,基本结构与`Mode 1`一样,唯一的不同在于每个itemView顶部留白的的方式。
63 | >通过设置`UITabelView`的`tableHeaderView`,来提供顶部的占位留白,CollectionView采用自定义`STCollectionView`的`collectionHeaderView`来实现占位留白。(目前不支持`UIScrollView`)
64 |
65 |
66 | 2. 如何设置区分`Mode 1`与`Mode 2`模式?
67 | >正常条件下即为`Mode 1`模式;在`SwipeTableView.h`中或者在工程PCH文件中设置宏`#define ST_PULLTOREFRESH_HEADER_HEIGHT xx`设置为`Mode 2`模式。
68 |
69 |
70 |
71 | ## 使用用法
72 | ### 怎样使用?使用方式类似UITableView
73 |
74 | **实现 `SwipeTableViewDataSource` 代理的两个方法:**
75 |
76 | ```objc
77 | - (NSInteger)numberOfItemsInSwipeTableView:(SwipeTableView *)swipeView
78 | ```
79 | >返回列表item的个数
80 |
81 |
82 | ```objc
83 | - (UIScrollView *)swipeTableView:(SwipeTableView *)swipeView viewForItemAtIndex:(NSInteger)index reusingView:(UIScrollView *)view
84 | ```
85 | >返回对应index下的itemView,返回的视图类型需要是`UIScrollView`及其子类:`UITableView`或者`UICollectionView`。这里采用重用机制,需要根据reusingView来创建单一的itemView。
86 |
87 | **使用的`swipeHeaderView`必须是`STHeaderView`及其子类的实例。**
88 |
89 |
90 | ### 如何支持下拉刷新?
91 |
92 | >**下拉刷新有两种实现方式,一种用户自定义下拉刷新组件(局部修改自定义),一种是简单粗暴设置宏:**
93 |
94 |
95 | **1. 一行代码支持常用的下拉刷新控件,只需要在项目的PCH文件中或者在`SwipeTableView.h`文件中设置如下的宏:**
96 |
97 | ```objc
98 | #define ST_PULLTOREFRESH_HEADER_HEIGHT xx
99 | ```
100 |
101 | >上述宏中的`xx`要与您使用的第三方下拉刷新控件的refreshHeader高度相同:
102 | `MJRefresh` 为 `MJRefreshHeaderHeight`,`SVPullToRefresh` 为 `SVPullToRefreshViewHeight`(注:此时视图结构为`Model 2`)
103 |
104 |
105 | 新增下拉刷新代理,可以控制每个item下拉临界高度,并自由控制每个item是否支持下拉刷新
106 |
107 | ```objc
108 | - (BOOL)swipeTableView:(SwipeTableView *)swipeTableView shouldPullToRefreshAtIndex:(NSInteger)index
109 | ```
110 | >根据item所在index,设置item是否支持下拉刷新。**在设置`#define ST_PULLTOREFRESH_HEADER_HEIGHT xx`的时候默认是YES(全部支持),否则默认为NO。**
111 |
112 |
113 | ```objc
114 | - (CGFloat)swipeTableView:(SwipeTableView *)swipeTableView heightForRefreshHeaderAtIndex:(NSInteger)index
115 | ```
116 | >返回对应item下拉刷新的临界高度,如果没有实现此代理,在设置`#define ST_PULLTOREFRESH_HEADER_HEIGHT xx`的时候默认是`ST_PULLTOREFRESH_HEADER_HEIGHT`的高度。**如果没有设置宏,并且想要自定义修改下拉刷新,必须实现此代理,提供下拉刷新控件RefreshHeader的高度(RefreshHeader全部露出的高度),来通知`SwipeTableView`触发下拉刷新。**
117 |
118 |
119 | **2. 如果想要更好的扩展性,以及喜欢自己研究的同学,可以尝试修改或者自定义下拉控件来解决下拉刷新的兼容问题,同时这里提供一些思路:**
120 |
121 | 如果下拉刷新控件的frame是固定的(比如header的frame),这样可以在初始化下拉刷新的header或者在数据源的代理中重设下拉header的frame。
122 |
123 | >获取下拉刷新的header,将header的frame的y值减去`swipeHeaderView`与`swipeHeaderBar`的高度和(或者重写RefreshHeader的setFrame方法),就可以消除itemView contentInsets顶部留白top值的影响(否则添加的下拉header是隐藏在底部的)。
124 |
125 | ```objc
126 | - (UIScrollView *)swipeTableView:(SwipeTableView *)swipeView viewForItemAtIndex:(NSInteger)index reusingView:(UIScrollView *)view {
127 | ...
128 | STRefreshHeader * header = scrollView.header;
129 | header.y = - (header.height + (swipeHeaderView.height + swipeHeaderBar.height));
130 | ...
131 | }
132 |
133 |
134 | or
135 |
136 |
137 | - (instancetype)initWithFrame:(CGRect)frame {
138 | ...
139 | STRefreshHeader * header = [STRefreshHeader headerWithRefreshingBlock:^(STRefreshHeader *header) {
140 |
141 | }];
142 | header.y = - (header.height + (swipeHeaderView.height + swipeHeaderBar.height));
143 | scrollView.header = header;
144 | ...
145 | }
146 | ```
147 |
148 | 对于一些下拉刷新控件,RefreshHeader的frame设置可能会在`layoutSubviews`中,所以,对RefreshHeader frame的修改,需要等执行完`layouSubviews`之后,在 *有效的方法* 中操作,比如:
149 |
150 |
151 | ```objc
152 | - (void)scrollViewDidScroll:(UIScrollView *)scrollView {
153 | STRefreshHeader * header = self.header;
154 | CGFloat orginY = - (header.height + self.swipeTableView.swipeHeaderView.height + self.swipeTableView.swipeHeaderBar.height);
155 | if (header.y != orginY) {
156 | header.y = orginY;
157 | }
158 | }
159 | ```
160 |
161 |
162 | 如何判断下拉刷新的控件的frame是不是固定不变的呢?
163 |
164 | >一是可以研究源码查看RefreshHeader的frame是否固定不变;另一个简单的方式是,在ScrollView的滚动代理中log RefreshHeader的frame(大部分的下拉控件的frame都是固定的)。
165 |
166 |
167 | 如果使用的下拉刷新控件的frame是变化的(个人感觉极少数),那么只能更深层的修改下拉刷新控件或者自定义下拉刷新。也可以更直接的采用第一种设置宏的方式支持下拉刷新。
168 |
169 |
170 | ### 混合模式(UItableView & UICollectionView & UIScrollView)
171 |
172 | 1. 在`Mode 1`模式下,属于最基本的模式,可扩展性也是最强的,此时,支持`UITableView`、`UICollectionView`、`UIScrollView`。**如果,同时设置`shouldAdjustContentSize`为YES,实现自适应contentSize,在`UICollectionView`内容不足的添加下,只能使用`STCollectionView`及其子类**
173 |
174 | >**`UICollectionView`不支持通过contentSize属性设置contentSize。**
175 |
176 | 2. 在`Mode 2`模式下,**`SwipeTableView`支持的collectionView必须是`STCollectionView`及其子类的实例**,目前,不支持`UIScrollView`。
177 |
178 |
179 | ## **示例代码**:
180 |
181 | ### 初始化并设置header与bar
182 | ```objc
183 | self.swipeTableView = [[SwipeTableView alloc]initWithFrame:[UIScreen mainScreen].bounds];
184 | _swipeTableView.delegate = self;
185 | _swipeTableView.dataSource = self;
186 | _swipeTableView.shouldAdjustContentSize = YES;
187 | _swipeTableView.swipeHeaderView = self.tableViewHeader;
188 | _swipeTableView.swipeHeaderBar = self.segmentBar;
189 | ```
190 |
191 | ### 实现数据源代理:
192 | ```objc
193 | - (NSInteger)numberOfItemsInSwipeTableView:(SwipeTableView *)swipeView {
194 | return 4;
195 | }
196 |
197 | - (UIScrollView *)swipeTableView:(SwipeTableView *)swipeView viewForItemAtIndex:(NSInteger)index reusingView:(UIScrollView *)view {
198 | UITableView * tableView = view;
199 | if (nil == tableView) {
200 | UITableView * tableView = [[UITableView alloc]initWithFrame:swipeView.bounds style:UITableViewStylePlain];
201 | tableView.backgroundColor = [UIColor whiteColor];
202 | ...
203 | }
204 | // 这里刷新每个item的数据
205 | [tableVeiw refreshWithData:dataArray];
206 | ...
207 | return tableView;
208 | }
209 | ```
210 |
211 | ### `STCollectionView`使用方法:
212 | ```objc
213 | MyCollectionView.h
214 |
215 | @interface MyCollectionView : STCollectionView
216 |
217 | @property (nonatomic, assign) NSInteger numberOfItems;
218 | @property (nonatomic, assign) BOOL isWaterFlow;
219 |
220 | @end
221 |
222 |
223 |
224 | MyCollectionView.m
225 |
226 | - (instancetype)initWithFrame:(CGRect)frame {
227 |
228 | self = [super initWithFrame:frame];
229 | if (self) {
230 | STCollectionViewFlowLayout * layout = self.st_collectionViewLayout;
231 | layout.minimumInteritemSpacing = 5;
232 | layout.minimumLineSpacing = 5;
233 | layout.sectionInset = UIEdgeInsetsMake(5, 5, 5, 5);
234 | self.stDelegate = self;
235 | self.stDataSource = self;
236 | [self registerClass:UICollectionViewCell.class forCellWithReuseIdentifier:@"item"];
237 | [self registerClass:UICollectionReusableView.class forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"header"];
238 | [self registerClass:UICollectionReusableView.class forSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:@"footer"];
239 | }
240 | return self;
241 | }
242 |
243 |
244 | - (NSInteger)collectionView:(UICollectionView *)collectionView layout:(STCollectionViewFlowLayout *)layout numberOfColumnsInSection:(NSInteger)section {
245 | return _numberOfColumns;
246 | }
247 |
248 | - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
249 | return CGSizeMake(0, 100);
250 | }
251 |
252 | - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section {
253 | return CGSizeMake(kScreenWidth, 35);
254 | }
255 |
256 | - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout referenceSizeForFooterInSection:(NSInteger)section {
257 | return CGSizeMake(kScreenWidth, 35);
258 | }
259 |
260 | - (UICollectionReusableView *)stCollectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath {
261 | UICollectionReusableView * reusableView = nil;
262 | if ([kind isEqualToString:UICollectionElementKindSectionHeader]) {
263 | reusableView = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"header" forIndexPath:indexPath];
264 | // custom UI......
265 | }else if ([kind isEqualToString:UICollectionElementKindSectionFooter]) {
266 | reusableView = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:@"footer" forIndexPath:indexPath];
267 | // custom UI......
268 | }
269 | return reusableView;
270 | }
271 |
272 | - (NSInteger)numberOfSectionsInStCollectionView:(UICollectionView *)collectionView {
273 | return _numberOfSections;
274 | }
275 |
276 | - (NSInteger)stCollectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
277 | return _numberOfItems;
278 | }
279 |
280 | - (UICollectionViewCell *)stCollectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
281 | UICollectionViewCell * cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"item" forIndexPath:indexPath];
282 | // do something .......
283 | return cell;
284 | }
285 |
286 | ```
287 |
288 | **如果`STCollectionViewFlowLayout`已经不能满足`UICollectionView`的布局的话,用户自定义的`flowlayout`需要继承自`STCollectionViewFlowLayout`,并在重写相应方法的时候需要调用父类方法,并需要遵循一定规则,如下:**
289 |
290 |
291 | ```objc
292 | - (void)prepareLayout {
293 | [super prepareLayout];
294 | // do something in sub class......
295 | }
296 |
297 | - (NSArray *)layoutAttributesForElementsInRect:(CGRect)rect {
298 | NSArray * superAttrs = [super layoutAttributesForElementsInRect:rect];
299 | NSMutableArray * itemAttrs = [superAttrs mutableCopy];
300 |
301 | // filter subClassAttrs to rect
302 | NSArray * filteredSubClassAttrs = ........;
303 |
304 | [itemAttrs addObjectsFromArray:fittesSubClassAttrs];
305 |
306 | return itemAttrs;
307 | }
308 |
309 | - (CGSize)collectionViewContentSize {
310 | CGSize superSize = [super collectionViewContentSize];
311 |
312 | CGSize subClassSize = .......;
313 | subClassSize.height += superSize.height;
314 |
315 | // fit mincontentSize
316 | STCollectionView * collectionView = (STCollectionView *)self.collectionView;
317 | subClassSize.height = fmax(subClassSize.height, collectionView.minRequireContentSize.height);
318 |
319 | return subClassSize;
320 | }
321 |
322 | ```
323 |
324 |
325 | ## Demo 介绍
326 | ### 使用的详细用法在SwipeTableViewDemo文件夹中,提供了五种示例:
327 |
328 | - `SingleOneKindView`
329 | 数据源提供的是单一类型的itemView,这里默认提供的是 `CustomTableView` (`UITableView`的子类),并且每一个itemView的数据行数有多有少,因此在滑动到数据少的itemView时,再次触碰界面,当前的itemView会有回弹的动作(由于contentSize小的缘故)。
330 |
331 | - `HybridItemViews`
332 | 数据源提供的itemView类型是混合的,即 `CustomTableView` 与 `CustomCollectionView` (`UICollectionView`的子类)。
333 |
334 | -
`AdjustContentSize`
335 | 自适应调整cotentOffszie属性,这里不同的itemView的数据行数有多有少,当滑动到数据较少的itemView时,再次触碰界面并不会导致当前itemView的回弹,这里当前数据少的itemView已经做了最小contentSize的设置。
在0.2.3版本中去除了 demo 中的这一模块,默认除了`SingleOneKindView`模式下全部是自适应 contentSize。
336 |
337 | - `DisabledBarScroll`
338 | 取消顶部控制条的跟随滚动,只有在swipeHeaderView是nil的条件下才能生效。这样可以实现一个类似网易新闻首页的滚动菜单列表的布局。
339 |
340 | - `HiddenNavigationBar`
341 | 隐藏导航。自定义了一个返回按钮(支持手势滑动返回)。
342 |
343 | - Demo支持添加移除header(定义的`UIImageView`)与bar(自定义的 `CutomSegmentControl` )的功能。
344 |
345 | - 示例代码新增点击图片全屏查看。
346 |
347 | - Demo中提供简单的自定义下拉刷新控件`STRefreshHeader`,供参考
348 |
349 | # License
350 | SwipeTableView is available under the MIT license. See the LICENSE file for more info.
351 |
352 |
--------------------------------------------------------------------------------
/README_EN.md:
--------------------------------------------------------------------------------
1 | 
2 |
3 | [](http://cocoapods.org/pods/SwipeTableView)
4 | 
5 | [](https://github.com/Roylee-ML/SwipeTableView/blob/master/License)
6 |
7 | This component support the UITableview scroll up and down, and both support switch between two list horizontally.At the same time it set a header and a segment bar at the top of list view, the usage is similar to the native UITableview tableHeaderView way.
8 |
9 | ⚠️**NOTE**: This component has been deprecated due to its unintuitive design. For similar functionality, please refer to [HBHybridCollectionView](https://github.com/Ban-Tang/HBHybridCollectionView), which is more stable and reliable.
10 | ****
11 |
12 | # Overview
13 |
14 |
15 |
16 |
17 |
18 |
19 | # Quick start
20 |
21 | SwipeTableView is available on [CocoaPods](http://cocoapods.org). Add the following to your Podfile:
22 |
23 | ```ruby
24 | pod 'SwipeTableView'
25 | ```
26 |
27 |
28 | # Catalog
29 |
30 | 1. [Principle](https://github.com/Roylee-ML/SwipeTableView/blob/master/README_EN.md#principle)
31 | 2. [Base Usage](https://github.com/Roylee-ML/SwipeTableView/blob/master/README_EN.md#how-to-use-it-just-like-uitableview)
32 | 3. [Pull To Refresh](https://github.com/Roylee-ML/SwipeTableView/blob/master/README_EN.md#how-to-support-pull-to-refersh)
33 | 4. [Hybrid Items](https://github.com/Roylee-ML/SwipeTableView/blob/master/README_EN.md#hybrid-uitableview--uicollectionview--uiscrollview)
34 | 5. [Example Code](https://github.com/Roylee-ML/SwipeTableView/blob/master/README_EN.md#example-code)
35 | 6. [Demo Info](https://github.com/Roylee-ML/SwipeTableView/blob/master/README_EN.md#detailed-usages-are-in-the-swipetableviewdemo-folder-provide-five-examples)
36 |
37 |
38 | ## Principle
39 | >In order to be compatible with the pull to refresh, adopted two kinds of ways, but the basic structure is the same.
40 |
41 | ### Mode 1
42 |
43 | 
44 |
45 | 1. Use`UICollectionView`as a contentview for items,to enable scroll horizontally.
46 |
47 | 2. After supporting the horizontal scrolling, the most pivotal issue is the alignment of neighboring items after scroll horizontally.
48 | >For the alignment of two itemViews after scroll, should compared to the contentOffsets of the two itemViews, and then set the contentOffset of the nest itemView same as the previous one. By this way, the offset of the itemView is aligned after scroll horizontally.
49 |
50 | 3. Since the itemViews share a header and bar, so, the header and bar must be the subview of the root view, that is, the same as the CollectionView which is subview of `SwipeTableView`, and above the CollectionView.
51 | >For support sticky of headr & bar, KVO observe the contentOffset of current itemView. And then change the Y frame of header and bar when the contentOffset of current itemView changed.
52 |
53 | 4. Because he top header & bar are at the top, so the head of each itemView need make a blank space for header & bar display. In `Model 1`, the way is modify the top contentInsets of `UIScrollView` to set top blank space.
54 |
55 | 5. Due to the header is at the top of the layer, so if the current itemView should scroll follow with header when pan scroll the header, need to reset the contentOffset of current ItemView when header's frame changed. And the header must have a elasticity effect same as UIScrollview.
56 | >Here, use the `UIKit Dynamic` physical animation engine to customize the `STHeaderView`, achieve the custom `UIScrollView` effect to solve the problems above [`Reference`](http://holko.pl/2014/07/06/inertia-bouncing-rubber-banding-uikit-dynamics/).
57 |
58 |
59 | ### Mode 2
60 |
61 | 
62 |
63 | 1. In `Mode 2`, the basic structure sames as `Mode 1`, the only difference is that the top balnk of each itemView.
64 | >By setting `tableHeaderView` of `UITabelView` to provide top space blank, CollectionView item should use custom `collectionHeaderView` of `STCollectionView` for set the blank. (Current mode does not support `UIScrollView`)
65 |
66 |
67 |
68 | 2. How to distinguish `Mode 1` from `Mode 2`?
69 | >Under normal conditions, it is `Mode 1`; For `Mode 2`, set the macro `#define ST_PULLTOREFRESH_HEADER_HEIGHT xx` in the `SwipeTableView.h` or the PCH file.
70 |
71 |
72 | ## Basic Usage
73 |
74 | ### How to use it? Just like UITableView
75 |
76 | **Conform protocol `SwipeTableViewDataSource` and implement the two methods below:**
77 |
78 | ```objc
79 | - (NSInteger)numberOfItemsInSwipeTableView:(SwipeTableView *)swipeView
80 | ```
81 | >Return a count of the itemViews.
82 |
83 |
84 |
85 | ```objc
86 | - (UIScrollView *)swipeTableView:(SwipeTableView *)swipeView viewForItemAtIndex:(NSInteger)index reusingView:(UIScrollView *)view
87 | ```
88 | >Return a itemView at the index,the itemView must be kind of `UIScrollView`、`UITableView` or `UICollectionView`. It completed by reuse mechanism, so it is based the reusingView when create a itemView.
89 |
90 |
91 | **The `swipeHeaderView` must be `STHeaderView` or subclass of `STHeaderView`**
92 |
93 |
94 | ### How to support pull to refersh?
95 |
96 | >**There is two ways to support pull to refresh, one is custom pull to refresh by yourself(just custom part), another is set a macro simply and crudely**
97 |
98 |
99 |
100 |
101 | **1. Support pull to refersh by one line code, juset set the macro below in `SwipeTableView.h` or the PCH file:**
102 |
103 | ```objc
104 | #define ST_PULLTOREFRESH_HEADER_HEIGHT xx
105 | ```
106 |
107 | >The `xx` of macro above should be same as the height of your third pull to refresh component:
108 | `MJRefresh` is `MJRefreshHeaderHeight`, `SVPullToRefresh` is `SVPullToRefreshViewHeight` (Note: current mode is `Mode 2`)
109 |
110 |
111 | Add a protocol of refresh, now you can set the top height of each itemView when began refresh, and set should supports pull to refresh for each item freely.
112 |
113 | ```objc
114 | - (BOOL)swipeTableView:(SwipeTableView *)swipeTableView shouldPullToRefreshAtIndex:(NSInteger)index
115 | ```
116 | >Set the item should supports pull to refresh at the index. **Default is Yes When set macro `#define ST_PULLTOREFRESH_HEADER_HEIGHT xx`, otherwise is NO.**
117 |
118 |
119 | ```objc
120 | - (CGFloat)swipeTableView:(SwipeTableView *)swipeTableView heightForRefreshHeaderAtIndex:(NSInteger)index
121 | ```
122 | >Return a height of the itemView when began refresh, if not implement this method, the default height is `ST_PULLTOREFRESH_HEADER_HEIGHT` when you set the macro `#define ST_PULLTOREFRESH_HEADER_HEIGHT xx`.**If you didn't set the refresh macro, and want to support pull to refresh by custom the refresh, you must implement this method, and provide a height of the RefreshHeader(A height when the RefreshHeader show wholly), to notify `SwipeTableView` call the pull to refresh**
123 |
124 |
125 | **2. If you want a better extension, as well as students who likes research, you can try to modify or custom a refresh control to solve the problem of pull to refresh, while here provide some ideas:**
126 |
127 | If the frame of refresh control is fixed (such as frame of refresh header), you can reset the frame of refresh header when init it, or reset the frame in the datasource of SwipeTableViewDataSource.
128 |
129 | >Get the refresh header, and change Y of the frame, subtract both heights of `swipeHeaderView` and `swipeHeaderBar`(or override method `setFrame:` of RefreshHeader). So this way can solve the effect of top contentInsets of the itemVewi(othewise, the frefresh header will below the `swipeHeaderView`).
130 |
131 |
132 | ```objc
133 | - (UIScrollView *)swipeTableView:(SwipeTableView *)swipeView viewForItemAtIndex:(NSInteger)index reusingView:(UIScrollView *)view {
134 | ...
135 | STRefreshHeader * header = scrollView.header;
136 | header.y = - (header.height + (swipeHeaderView.height + swipeHeaderBar.height));
137 | ...
138 | }
139 |
140 |
141 | or
142 |
143 |
144 | - (instancetype)initWithFrame:(CGRect)frame {
145 | ...
146 | STRefreshHeader * header = [STRefreshHeader headerWithRefreshingBlock:^(STRefreshHeader *header) {
147 |
148 | }];
149 | header.y = - (header.height + (swipeHeaderView.height + swipeHeaderBar.height));
150 | scrollView.header = header;
151 | ...
152 | }
153 | ```
154 |
155 | For some refreh control component, the frame of RefreshHeader will be set in mehtod `layoutSubviews`, so we should change the frame of RefreshHeader after execute `layouSubviews` of RefreshHeader, such as:
156 |
157 |
158 | ```objc
159 | - (void)scrollViewDidScroll:(UIScrollView *)scrollView {
160 | STRefreshHeader * header = self.header;
161 | CGFloat orginY = - (header.height + self.swipeTableView.swipeHeaderView.height + self.swipeTableView.swipeHeaderBar.height);
162 | if (header.y != orginY) {
163 | header.y = orginY;
164 | }
165 | }
166 | ```
167 |
168 |
169 | How to judge the frame of the RefreshHeader of refresh control is constant?
170 |
171 | >One way is check out the source code of the refresh control; The other way is simple, just log the frame of RefreshHeader when scroll the itemView(most RefreshHeader height of third refresh control is constant).
172 |
173 |
174 |
175 | ### Hybrid (UItableView & UICollectionView & UIScrollView)
176 |
177 | 1. In basic mode `Model 1`, has the best extensibility, it supports `UITableView`、`UICollectionView`、`UIScrollView`.**If you set the property `shouldAdjustContentSize` YES to adjust the contentSize of itemView, you shuld only use `STCollectionView` its subcalss when your itemView is `UICollectionView` and its contentinfo is less**
178 |
179 | >**`UICollectionView` can not set contentSize by property contentSize.**
180 |
181 | 2. In `Model 2`, **collectionView you used must be kind of `SwipeTableView`**, now, not support `UIScrollView`.
182 |
183 |
184 | ## **Example Code**:
185 | ### Init, set header and bar
186 |
187 | ```objc
188 | self.swipeTableView = [[SwipeTableView alloc]initWithFrame:[UIScreen mainScreen].bounds];
189 | _swipeTableView.delegate = self;
190 | _swipeTableView.dataSource = self;
191 | _swipeTableView.shouldAdjustContentSize = YES;
192 | _swipeTableView.swipeHeaderView = self.tableViewHeader;
193 | _swipeTableView.swipeHeaderBar = self.segmentBar;
194 |
195 | ```
196 |
197 | ### Conform the protocol:
198 |
199 | ```objc
200 | - (NSInteger)numberOfItemsInSwipeTableView:(SwipeTableView *)swipeView {
201 | return 4;
202 | }
203 |
204 | - (UIScrollView *)swipeTableView:(SwipeTableView *)swipeView viewForItemAtIndex:(NSInteger)index reusingView:(UIScrollView *)view {
205 | UITableView * tableView = view;
206 | if (nil == tableView) {
207 | UITableView * tableView = [[UITableView alloc]initWithFrame:swipeView.bounds style:UITableViewStylePlain];
208 | tableView.backgroundColor = [UIColor whiteColor];
209 | ...
210 | }
211 | // 这里刷新每个item的数据
212 | [tableVeiw refreshWithData:dataArray];
213 | ...
214 | return tableView;
215 | }
216 | ```
217 |
218 | ### How to use `STCollectionView`:
219 |
220 | ```objc
221 | MyCollectionView.h
222 |
223 | @interface MyCollectionView : STCollectionView
224 |
225 | @property (nonatomic, assign) NSInteger numberOfItems;
226 | @property (nonatomic, assign) BOOL isWaterFlow;
227 |
228 | @end
229 |
230 |
231 |
232 | MyCollectionView.m
233 |
234 | - (instancetype)initWithFrame:(CGRect)frame {
235 |
236 | self = [super initWithFrame:frame];
237 | if (self) {
238 | STCollectionViewFlowLayout * layout = self.st_collectionViewLayout;
239 | layout.minimumInteritemSpacing = 5;
240 | layout.minimumLineSpacing = 5;
241 | layout.sectionInset = UIEdgeInsetsMake(5, 5, 5, 5);
242 | self.stDelegate = self;
243 | self.stDataSource = self;
244 | [self registerClass:UICollectionViewCell.class forCellWithReuseIdentifier:@"item"];
245 | [self registerClass:UICollectionReusableView.class forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"header"];
246 | [self registerClass:UICollectionReusableView.class forSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:@"footer"];
247 | }
248 | return self;
249 | }
250 |
251 |
252 | - (NSInteger)collectionView:(UICollectionView *)collectionView layout:(STCollectionViewFlowLayout *)layout numberOfColumnsInSection:(NSInteger)section {
253 | return _numberOfColumns;
254 | }
255 |
256 | - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
257 | return CGSizeMake(0, 100);
258 | }
259 |
260 | - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section {
261 | return CGSizeMake(kScreenWidth, 35);
262 | }
263 |
264 | - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout referenceSizeForFooterInSection:(NSInteger)section {
265 | return CGSizeMake(kScreenWidth, 35);
266 | }
267 |
268 | - (UICollectionReusableView *)stCollectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath {
269 | UICollectionReusableView * reusableView = nil;
270 | if ([kind isEqualToString:UICollectionElementKindSectionHeader]) {
271 | reusableView = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"header" forIndexPath:indexPath];
272 | // custom UI......
273 | }else if ([kind isEqualToString:UICollectionElementKindSectionFooter]) {
274 | reusableView = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:@"footer" forIndexPath:indexPath];
275 | // custom UI......
276 | }
277 | return reusableView;
278 | }
279 |
280 | - (NSInteger)numberOfSectionsInStCollectionView:(UICollectionView *)collectionView {
281 | return _numberOfSections;
282 | }
283 |
284 | - (NSInteger)stCollectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
285 | return _numberOfItems;
286 | }
287 |
288 | - (UICollectionViewCell *)stCollectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
289 | UICollectionViewCell * cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"item" forIndexPath:indexPath];
290 | // do something .......
291 | return cell;
292 | }
293 |
294 | ```
295 |
296 | **If `STCollectionViewFlowLayout` can not satisfy the layout of `UICollectionView`, you can custom a `flowlayout` subcalss of `STCollectionViewFlowLayout`, And need to call call the parent class method and follow some rules when override methods, such as:**
297 |
298 |
299 | ```objc
300 | - (void)prepareLayout {
301 | [super prepareLayout];
302 | // do something in sub class......
303 | }
304 |
305 | - (NSArray *)layoutAttributesForElementsInRect:(CGRect)rect {
306 | NSArray * superAttrs = [super layoutAttributesForElementsInRect:rect];
307 | NSMutableArray * itemAttrs = [superAttrs mutableCopy];
308 |
309 | // filter subClassAttrs to rect
310 | NSArray * filteredSubClassAttrs = ........;
311 |
312 | [itemAttrs addObjectsFromArray:fittesSubClassAttrs];
313 |
314 | return itemAttrs;
315 | }
316 |
317 | - (CGSize)collectionViewContentSize {
318 | CGSize superSize = [super collectionViewContentSize];
319 |
320 | CGSize subClassSize = .......;
321 | subClassSize.height += superSize.height;
322 |
323 | // fit mincontentSize
324 | STCollectionView * collectionView = (STCollectionView *)self.collectionView;
325 | subClassSize.height = fmax(subClassSize.height, collectionView.minRequireContentSize.height);
326 |
327 | return subClassSize;
328 | }
329 |
330 | ```
331 |
332 |
333 | ## Demo Info
334 |
335 | ### Detailed usages are in the SwipeTableViewDemo folder, provide five examples:
336 |
337 | - `SingleOneKindView`
338 | The itemView is just one kind, it is `CustomTableView` (subclass of `UITableView`) in the demo
339 |
340 | - `HybridItemViews`
341 | The itemViews which dataSource provided are hybird, they are `CustomTableView` `CustomCollectionView`(subclass of `UICollectionView`) in the demo
342 |
343 | - `AdjustContentSize`
344 | Adjust the cotentOffszie to fit screen when the data is less than screen.
In release 0.2.3, delete this module in the demo, in module `SingleOneKindView` default is adjsut contentSize.
345 |
346 | - `DisabledBarScroll`
347 | Disabel the segment scrolling when scroll the itemView, it is available when swipeHeaderView is nill.
348 |
349 | - `HiddenNavigationBar`
350 | Hidden the nabigationbar. Have a back button, and support slide back.
351 |
352 | - In the Demo, you can add or delete the header or bar.
353 |
354 | - Tap the header can view the image in screen.
355 |
356 | - Custom pull to refresh component `STRefreshHeader`, for reference only
357 |
358 | # License
359 |
360 | SwipeTableView is available under the MIT license. See the LICENSE file for more info.
361 |
362 |
--------------------------------------------------------------------------------
/ScreenShots/SwipeTableViewStruct1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/liangdrime/SwipeTableView/ffdc47708ca33ee209ae09c9433f71d1463dacc2/ScreenShots/SwipeTableViewStruct1.png
--------------------------------------------------------------------------------
/ScreenShots/SwipeTableViewStruct2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/liangdrime/SwipeTableView/ffdc47708ca33ee209ae09c9433f71d1463dacc2/ScreenShots/SwipeTableViewStruct2.png
--------------------------------------------------------------------------------
/ScreenShots/logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/liangdrime/SwipeTableView/ffdc47708ca33ee209ae09c9433f71d1463dacc2/ScreenShots/logo.png
--------------------------------------------------------------------------------
/ScreenShots/screenshot1.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/liangdrime/SwipeTableView/ffdc47708ca33ee209ae09c9433f71d1463dacc2/ScreenShots/screenshot1.gif
--------------------------------------------------------------------------------
/ScreenShots/screenshot2.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/liangdrime/SwipeTableView/ffdc47708ca33ee209ae09c9433f71d1463dacc2/ScreenShots/screenshot2.gif
--------------------------------------------------------------------------------
/ScreenShots/screenshot3.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/liangdrime/SwipeTableView/ffdc47708ca33ee209ae09c9433f71d1463dacc2/ScreenShots/screenshot3.gif
--------------------------------------------------------------------------------
/SwipeTableView.podspec:
--------------------------------------------------------------------------------
1 | Pod::Spec.new do |s|
2 |
3 | s.name = "SwipeTableView"
4 | s.version = "0.2.6"
5 | s.summary = "A swipe view with tableview oc iOS."
6 | s.description = <<-DESC
7 | It is a swipe view with tableview items,so it support scroll vertical and horizontal.It's used just like a tableview to set header or swithcbar.
8 | DESC
9 |
10 | s.homepage = "https://github.com/Roylee-ML/SwipeTableView"
11 | # s.screenshots = "https://github.com/Roylee-ML/SwipeTableView/blob/master/ScreenShot/screenshot.gif"
12 | s.license = "MIT"
13 | # s.license = { :type => "MIT", :file => "FILE_LICENSE" }
14 | s.author = { "Roylee-ML" => "roylee.stillway@gmail.com" }
15 | # Or just: s.author = "Roylee-ML"
16 | # s.authors = { "Roylee-ML" => "roylee.stillway@gmail.com" }
17 | # s.social_media_url = "http://twitter.com/Roylee-ML"
18 | # s.platform = :ios
19 | s.platform = :ios, "7.0"
20 |
21 | # When using multiple platforms
22 | # s.ios.deployment_target = "5.0"
23 | # s.osx.deployment_target = "10.7"
24 | # s.watchos.deployment_target = "2.0"
25 | # s.tvos.deployment_target = "9.0"
26 |
27 | s.source = { :git => "https://github.com/Roylee-ML/SwipeTableView.git", :tag => s.version.to_s }
28 |
29 |
30 | s.source_files = "SwipeTableView/SwipeTableView/*.{h,m}"
31 | # s.public_header_files = "Classes/**/*.h"
32 |
33 | # s.framework = "UIKit"
34 | s.frameworks = "Foundation", "UIKit"
35 |
36 | # s.library = "iconv"
37 | # s.libraries = "iconv", "xml2"
38 |
39 | s.requires_arc = true
40 |
41 | # s.xcconfig = { "HEADER_SEARCH_PATHS" => "$(SDKROOT)/usr/include/libxml2" }
42 | # s.dependency "JSONKit", "~> 1.4"
43 |
44 | end
45 |
--------------------------------------------------------------------------------
/SwipeTableView.xcodeproj/project.pbxproj:
--------------------------------------------------------------------------------
1 | // !$*UTF8*$!
2 | {
3 | archiveVersion = 1;
4 | classes = {
5 | };
6 | objectVersion = 46;
7 | objects = {
8 |
9 | /* Begin PBXBuildFile section */
10 | 7D1C83FC1D2416B7001859EB /* STCollectionView.m in Sources */ = {isa = PBXBuildFile; fileRef = 7D1C83FB1D2416B7001859EB /* STCollectionView.m */; };
11 | 7D239A0B1D1D84DB004FF025 /* STHeaderView.m in Sources */ = {isa = PBXBuildFile; fileRef = 7D239A0A1D1D84DB004FF025 /* STHeaderView.m */; };
12 | 7D2C2AB01D32A7AD00C6A234 /* onepiece_kiudai.png in Resources */ = {isa = PBXBuildFile; fileRef = 7D2C2A951D32A7AD00C6A234 /* onepiece_kiudai.png */; };
13 | 7D2C2AB11D32A7AD00C6A234 /* STImageController.m in Sources */ = {isa = PBXBuildFile; fileRef = 7D2C2A981D32A7AD00C6A234 /* STImageController.m */; };
14 | 7D2C2AB21D32A7AD00C6A234 /* STListController.m in Sources */ = {isa = PBXBuildFile; fileRef = 7D2C2A9A1D32A7AD00C6A234 /* STListController.m */; };
15 | 7D2C2AB41D32A7AD00C6A234 /* STViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 7D2C2A9E1D32A7AD00C6A234 /* STViewController.m */; };
16 | 7D2C2AB51D32A7AD00C6A234 /* github.png in Resources */ = {isa = PBXBuildFile; fileRef = 7D2C2AA01D32A7AD00C6A234 /* github.png */; };
17 | 7D2C2AB61D32A7AD00C6A234 /* STRefreshHeader.m in Sources */ = {isa = PBXBuildFile; fileRef = 7D2C2AA31D32A7AD00C6A234 /* STRefreshHeader.m */; };
18 | 7D2C2AB71D32A7AD00C6A234 /* UIScrollView+STRefresh.m in Sources */ = {isa = PBXBuildFile; fileRef = 7D2C2AA51D32A7AD00C6A234 /* UIScrollView+STRefresh.m */; };
19 | 7D2C2AB81D32A7AD00C6A234 /* STTransitions.m in Sources */ = {isa = PBXBuildFile; fileRef = 7D2C2AA81D32A7AD00C6A234 /* STTransitions.m */; };
20 | 7D2C2AB91D32A7AD00C6A234 /* CustomCollectionView.m in Sources */ = {isa = PBXBuildFile; fileRef = 7D2C2AAB1D32A7AD00C6A234 /* CustomCollectionView.m */; };
21 | 7D2C2ABA1D32A7AD00C6A234 /* CustomSegmentControl.m in Sources */ = {isa = PBXBuildFile; fileRef = 7D2C2AAD1D32A7AD00C6A234 /* CustomSegmentControl.m */; };
22 | 7D2C2ABB1D32A7AD00C6A234 /* CustomTableView.m in Sources */ = {isa = PBXBuildFile; fileRef = 7D2C2AAF1D32A7AD00C6A234 /* CustomTableView.m */; };
23 | 7DFB6ACE1CAEBCC600C2F0D3 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 7DFB6ACD1CAEBCC600C2F0D3 /* main.m */; };
24 | 7DFB6AD11CAEBCC600C2F0D3 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 7DFB6AD01CAEBCC600C2F0D3 /* AppDelegate.m */; };
25 | 7DFB6AD71CAEBCC600C2F0D3 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 7DFB6AD51CAEBCC600C2F0D3 /* Main.storyboard */; };
26 | 7DFB6AD91CAEBCC600C2F0D3 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 7DFB6AD81CAEBCC600C2F0D3 /* Assets.xcassets */; };
27 | 7DFB6ADC1CAEBCC600C2F0D3 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 7DFB6ADA1CAEBCC600C2F0D3 /* LaunchScreen.storyboard */; };
28 | 7DFB6AE71CAEBCC600C2F0D3 /* SwipeTableViewTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 7DFB6AE61CAEBCC600C2F0D3 /* SwipeTableViewTests.m */; };
29 | 7DFB6AF41CAEBCEB00C2F0D3 /* SwipeTableView.m in Sources */ = {isa = PBXBuildFile; fileRef = 7DFB6AF31CAEBCEB00C2F0D3 /* SwipeTableView.m */; };
30 | 7DFB6AF71CAEBCFA00C2F0D3 /* UIView+STFrame.m in Sources */ = {isa = PBXBuildFile; fileRef = 7DFB6AF61CAEBCFA00C2F0D3 /* UIView+STFrame.m */; };
31 | /* End PBXBuildFile section */
32 |
33 | /* Begin PBXContainerItemProxy section */
34 | 7DFB6AE31CAEBCC600C2F0D3 /* PBXContainerItemProxy */ = {
35 | isa = PBXContainerItemProxy;
36 | containerPortal = 7DFB6AC11CAEBCC600C2F0D3 /* Project object */;
37 | proxyType = 1;
38 | remoteGlobalIDString = 7DFB6AC81CAEBCC600C2F0D3;
39 | remoteInfo = SwipeTableView;
40 | };
41 | /* End PBXContainerItemProxy section */
42 |
43 | /* Begin PBXFileReference section */
44 | 7D1C83FA1D2416B7001859EB /* STCollectionView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; lineEnding = 0; path = STCollectionView.h; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.objcpp; };
45 | 7D1C83FB1D2416B7001859EB /* STCollectionView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; lineEnding = 0; path = STCollectionView.m; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.objc; };
46 | 7D239A091D1D84DB004FF025 /* STHeaderView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = STHeaderView.h; sourceTree = ""; };
47 | 7D239A0A1D1D84DB004FF025 /* STHeaderView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = STHeaderView.m; sourceTree = ""; };
48 | 7D2C2A951D32A7AD00C6A234 /* onepiece_kiudai.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = onepiece_kiudai.png; sourceTree = ""; };
49 | 7D2C2A971D32A7AD00C6A234 /* STImageController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = STImageController.h; sourceTree = ""; };
50 | 7D2C2A981D32A7AD00C6A234 /* STImageController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = STImageController.m; sourceTree = ""; };
51 | 7D2C2A991D32A7AD00C6A234 /* STListController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = STListController.h; sourceTree = ""; };
52 | 7D2C2A9A1D32A7AD00C6A234 /* STListController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = STListController.m; sourceTree = ""; };
53 | 7D2C2A9D1D32A7AD00C6A234 /* STViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = STViewController.h; sourceTree = ""; };
54 | 7D2C2A9E1D32A7AD00C6A234 /* STViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = STViewController.m; sourceTree = ""; };
55 | 7D2C2AA01D32A7AD00C6A234 /* github.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = github.png; sourceTree = ""; };
56 | 7D2C2AA11D32A7AD00C6A234 /* STRefresh.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = STRefresh.h; sourceTree = ""; };
57 | 7D2C2AA21D32A7AD00C6A234 /* STRefreshHeader.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = STRefreshHeader.h; sourceTree = ""; };
58 | 7D2C2AA31D32A7AD00C6A234 /* STRefreshHeader.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = STRefreshHeader.m; sourceTree = ""; };
59 | 7D2C2AA41D32A7AD00C6A234 /* UIScrollView+STRefresh.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIScrollView+STRefresh.h"; sourceTree = ""; };
60 | 7D2C2AA51D32A7AD00C6A234 /* UIScrollView+STRefresh.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIScrollView+STRefresh.m"; sourceTree = ""; };
61 | 7D2C2AA71D32A7AD00C6A234 /* STTransitions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = STTransitions.h; sourceTree = ""; };
62 | 7D2C2AA81D32A7AD00C6A234 /* STTransitions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = STTransitions.m; sourceTree = ""; };
63 | 7D2C2AAA1D32A7AD00C6A234 /* CustomCollectionView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CustomCollectionView.h; sourceTree = ""; };
64 | 7D2C2AAB1D32A7AD00C6A234 /* CustomCollectionView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CustomCollectionView.m; sourceTree = ""; };
65 | 7D2C2AAC1D32A7AD00C6A234 /* CustomSegmentControl.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CustomSegmentControl.h; sourceTree = ""; };
66 | 7D2C2AAD1D32A7AD00C6A234 /* CustomSegmentControl.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CustomSegmentControl.m; sourceTree = ""; };
67 | 7D2C2AAE1D32A7AD00C6A234 /* CustomTableView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CustomTableView.h; sourceTree = ""; };
68 | 7D2C2AAF1D32A7AD00C6A234 /* CustomTableView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CustomTableView.m; sourceTree = ""; };
69 | 7DFB6AC91CAEBCC600C2F0D3 /* SwipeTableView.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = SwipeTableView.app; sourceTree = BUILT_PRODUCTS_DIR; };
70 | 7DFB6ACD1CAEBCC600C2F0D3 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; };
71 | 7DFB6ACF1CAEBCC600C2F0D3 /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; };
72 | 7DFB6AD01CAEBCC600C2F0D3 /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; };
73 | 7DFB6AD61CAEBCC600C2F0D3 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; };
74 | 7DFB6AD81CAEBCC600C2F0D3 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; };
75 | 7DFB6ADB1CAEBCC600C2F0D3 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; };
76 | 7DFB6ADD1CAEBCC600C2F0D3 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; };
77 | 7DFB6AE21CAEBCC600C2F0D3 /* SwipeTableViewTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = SwipeTableViewTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
78 | 7DFB6AE61CAEBCC600C2F0D3 /* SwipeTableViewTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SwipeTableViewTests.m; sourceTree = ""; };
79 | 7DFB6AE81CAEBCC600C2F0D3 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; };
80 | 7DFB6AF21CAEBCEB00C2F0D3 /* SwipeTableView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SwipeTableView.h; sourceTree = ""; };
81 | 7DFB6AF31CAEBCEB00C2F0D3 /* SwipeTableView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; lineEnding = 0; path = SwipeTableView.m; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.objc; };
82 | 7DFB6AF51CAEBCFA00C2F0D3 /* UIView+STFrame.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIView+STFrame.h"; sourceTree = ""; };
83 | 7DFB6AF61CAEBCFA00C2F0D3 /* UIView+STFrame.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIView+STFrame.m"; sourceTree = ""; };
84 | /* End PBXFileReference section */
85 |
86 | /* Begin PBXFrameworksBuildPhase section */
87 | 7DFB6AC61CAEBCC600C2F0D3 /* Frameworks */ = {
88 | isa = PBXFrameworksBuildPhase;
89 | buildActionMask = 2147483647;
90 | files = (
91 | );
92 | runOnlyForDeploymentPostprocessing = 0;
93 | };
94 | 7DFB6ADF1CAEBCC600C2F0D3 /* Frameworks */ = {
95 | isa = PBXFrameworksBuildPhase;
96 | buildActionMask = 2147483647;
97 | files = (
98 | );
99 | runOnlyForDeploymentPostprocessing = 0;
100 | };
101 | /* End PBXFrameworksBuildPhase section */
102 |
103 | /* Begin PBXGroup section */
104 | 7D2C2A941D32A7AD00C6A234 /* SwipeTableViewDemo */ = {
105 | isa = PBXGroup;
106 | children = (
107 | 7D2C2A961D32A7AD00C6A234 /* STController */,
108 | 7D2C2A9F1D32A7AD00C6A234 /* STRefresh */,
109 | 7D2C2AA61D32A7AD00C6A234 /* STTransition */,
110 | 7D2C2AA91D32A7AD00C6A234 /* STView */,
111 | 7D2C2A951D32A7AD00C6A234 /* onepiece_kiudai.png */,
112 | );
113 | path = SwipeTableViewDemo;
114 | sourceTree = "";
115 | };
116 | 7D2C2A961D32A7AD00C6A234 /* STController */ = {
117 | isa = PBXGroup;
118 | children = (
119 | 7D2C2A991D32A7AD00C6A234 /* STListController.h */,
120 | 7D2C2A9A1D32A7AD00C6A234 /* STListController.m */,
121 | 7D2C2A9D1D32A7AD00C6A234 /* STViewController.h */,
122 | 7D2C2A9E1D32A7AD00C6A234 /* STViewController.m */,
123 | 7D2C2A971D32A7AD00C6A234 /* STImageController.h */,
124 | 7D2C2A981D32A7AD00C6A234 /* STImageController.m */,
125 | );
126 | path = STController;
127 | sourceTree = "";
128 | };
129 | 7D2C2A9F1D32A7AD00C6A234 /* STRefresh */ = {
130 | isa = PBXGroup;
131 | children = (
132 | 7D2C2AA01D32A7AD00C6A234 /* github.png */,
133 | 7D2C2AA11D32A7AD00C6A234 /* STRefresh.h */,
134 | 7D2C2AA21D32A7AD00C6A234 /* STRefreshHeader.h */,
135 | 7D2C2AA31D32A7AD00C6A234 /* STRefreshHeader.m */,
136 | 7D2C2AA41D32A7AD00C6A234 /* UIScrollView+STRefresh.h */,
137 | 7D2C2AA51D32A7AD00C6A234 /* UIScrollView+STRefresh.m */,
138 | );
139 | path = STRefresh;
140 | sourceTree = "";
141 | };
142 | 7D2C2AA61D32A7AD00C6A234 /* STTransition */ = {
143 | isa = PBXGroup;
144 | children = (
145 | 7D2C2AA71D32A7AD00C6A234 /* STTransitions.h */,
146 | 7D2C2AA81D32A7AD00C6A234 /* STTransitions.m */,
147 | );
148 | path = STTransition;
149 | sourceTree = "";
150 | };
151 | 7D2C2AA91D32A7AD00C6A234 /* STView */ = {
152 | isa = PBXGroup;
153 | children = (
154 | 7D2C2AAE1D32A7AD00C6A234 /* CustomTableView.h */,
155 | 7D2C2AAF1D32A7AD00C6A234 /* CustomTableView.m */,
156 | 7D2C2AAA1D32A7AD00C6A234 /* CustomCollectionView.h */,
157 | 7D2C2AAB1D32A7AD00C6A234 /* CustomCollectionView.m */,
158 | 7D2C2AAC1D32A7AD00C6A234 /* CustomSegmentControl.h */,
159 | 7D2C2AAD1D32A7AD00C6A234 /* CustomSegmentControl.m */,
160 | );
161 | path = STView;
162 | sourceTree = "";
163 | };
164 | 7DFB6AC01CAEBCC600C2F0D3 = {
165 | isa = PBXGroup;
166 | children = (
167 | 7DFB6ACB1CAEBCC600C2F0D3 /* SwipeTableView */,
168 | 7DFB6AE51CAEBCC600C2F0D3 /* SwipeTableViewTests */,
169 | 7DFB6ACA1CAEBCC600C2F0D3 /* Products */,
170 | );
171 | sourceTree = "";
172 | };
173 | 7DFB6ACA1CAEBCC600C2F0D3 /* Products */ = {
174 | isa = PBXGroup;
175 | children = (
176 | 7DFB6AC91CAEBCC600C2F0D3 /* SwipeTableView.app */,
177 | 7DFB6AE21CAEBCC600C2F0D3 /* SwipeTableViewTests.xctest */,
178 | );
179 | name = Products;
180 | sourceTree = "";
181 | };
182 | 7DFB6ACB1CAEBCC600C2F0D3 /* SwipeTableView */ = {
183 | isa = PBXGroup;
184 | children = (
185 | 7DFB6AF11CAEBCD600C2F0D3 /* SwipeTableView */,
186 | 7D2C2A941D32A7AD00C6A234 /* SwipeTableViewDemo */,
187 | 7DFB6ACF1CAEBCC600C2F0D3 /* AppDelegate.h */,
188 | 7DFB6AD01CAEBCC600C2F0D3 /* AppDelegate.m */,
189 | 7DFB6AD51CAEBCC600C2F0D3 /* Main.storyboard */,
190 | 7DFB6AD81CAEBCC600C2F0D3 /* Assets.xcassets */,
191 | 7DFB6ADA1CAEBCC600C2F0D3 /* LaunchScreen.storyboard */,
192 | 7DFB6ADD1CAEBCC600C2F0D3 /* Info.plist */,
193 | 7DFB6ACC1CAEBCC600C2F0D3 /* Supporting Files */,
194 | );
195 | path = SwipeTableView;
196 | sourceTree = "";
197 | };
198 | 7DFB6ACC1CAEBCC600C2F0D3 /* Supporting Files */ = {
199 | isa = PBXGroup;
200 | children = (
201 | 7DFB6ACD1CAEBCC600C2F0D3 /* main.m */,
202 | );
203 | name = "Supporting Files";
204 | sourceTree = "";
205 | };
206 | 7DFB6AE51CAEBCC600C2F0D3 /* SwipeTableViewTests */ = {
207 | isa = PBXGroup;
208 | children = (
209 | 7DFB6AE61CAEBCC600C2F0D3 /* SwipeTableViewTests.m */,
210 | 7DFB6AE81CAEBCC600C2F0D3 /* Info.plist */,
211 | );
212 | path = SwipeTableViewTests;
213 | sourceTree = "";
214 | };
215 | 7DFB6AF11CAEBCD600C2F0D3 /* SwipeTableView */ = {
216 | isa = PBXGroup;
217 | children = (
218 | 7DFB6AF21CAEBCEB00C2F0D3 /* SwipeTableView.h */,
219 | 7DFB6AF31CAEBCEB00C2F0D3 /* SwipeTableView.m */,
220 | 7D239A091D1D84DB004FF025 /* STHeaderView.h */,
221 | 7D239A0A1D1D84DB004FF025 /* STHeaderView.m */,
222 | 7D1C83FA1D2416B7001859EB /* STCollectionView.h */,
223 | 7D1C83FB1D2416B7001859EB /* STCollectionView.m */,
224 | 7DFB6AF51CAEBCFA00C2F0D3 /* UIView+STFrame.h */,
225 | 7DFB6AF61CAEBCFA00C2F0D3 /* UIView+STFrame.m */,
226 | );
227 | path = SwipeTableView;
228 | sourceTree = "";
229 | };
230 | /* End PBXGroup section */
231 |
232 | /* Begin PBXNativeTarget section */
233 | 7DFB6AC81CAEBCC600C2F0D3 /* SwipeTableView */ = {
234 | isa = PBXNativeTarget;
235 | buildConfigurationList = 7DFB6AEB1CAEBCC600C2F0D3 /* Build configuration list for PBXNativeTarget "SwipeTableView" */;
236 | buildPhases = (
237 | 7DFB6AC51CAEBCC600C2F0D3 /* Sources */,
238 | 7DFB6AC61CAEBCC600C2F0D3 /* Frameworks */,
239 | 7DFB6AC71CAEBCC600C2F0D3 /* Resources */,
240 | );
241 | buildRules = (
242 | );
243 | dependencies = (
244 | );
245 | name = SwipeTableView;
246 | productName = SwipeTableView;
247 | productReference = 7DFB6AC91CAEBCC600C2F0D3 /* SwipeTableView.app */;
248 | productType = "com.apple.product-type.application";
249 | };
250 | 7DFB6AE11CAEBCC600C2F0D3 /* SwipeTableViewTests */ = {
251 | isa = PBXNativeTarget;
252 | buildConfigurationList = 7DFB6AEE1CAEBCC600C2F0D3 /* Build configuration list for PBXNativeTarget "SwipeTableViewTests" */;
253 | buildPhases = (
254 | 7DFB6ADE1CAEBCC600C2F0D3 /* Sources */,
255 | 7DFB6ADF1CAEBCC600C2F0D3 /* Frameworks */,
256 | 7DFB6AE01CAEBCC600C2F0D3 /* Resources */,
257 | );
258 | buildRules = (
259 | );
260 | dependencies = (
261 | 7DFB6AE41CAEBCC600C2F0D3 /* PBXTargetDependency */,
262 | );
263 | name = SwipeTableViewTests;
264 | productName = SwipeTableViewTests;
265 | productReference = 7DFB6AE21CAEBCC600C2F0D3 /* SwipeTableViewTests.xctest */;
266 | productType = "com.apple.product-type.bundle.unit-test";
267 | };
268 | /* End PBXNativeTarget section */
269 |
270 | /* Begin PBXProject section */
271 | 7DFB6AC11CAEBCC600C2F0D3 /* Project object */ = {
272 | isa = PBXProject;
273 | attributes = {
274 | LastUpgradeCheck = 0720;
275 | ORGANIZATIONNAME = "Roy lee";
276 | TargetAttributes = {
277 | 7DFB6AC81CAEBCC600C2F0D3 = {
278 | CreatedOnToolsVersion = 7.2;
279 | DevelopmentTeam = 437D87LT4G;
280 | };
281 | 7DFB6AE11CAEBCC600C2F0D3 = {
282 | CreatedOnToolsVersion = 7.2;
283 | TestTargetID = 7DFB6AC81CAEBCC600C2F0D3;
284 | };
285 | };
286 | };
287 | buildConfigurationList = 7DFB6AC41CAEBCC600C2F0D3 /* Build configuration list for PBXProject "SwipeTableView" */;
288 | compatibilityVersion = "Xcode 3.2";
289 | developmentRegion = English;
290 | hasScannedForEncodings = 0;
291 | knownRegions = (
292 | en,
293 | Base,
294 | );
295 | mainGroup = 7DFB6AC01CAEBCC600C2F0D3;
296 | productRefGroup = 7DFB6ACA1CAEBCC600C2F0D3 /* Products */;
297 | projectDirPath = "";
298 | projectRoot = "";
299 | targets = (
300 | 7DFB6AC81CAEBCC600C2F0D3 /* SwipeTableView */,
301 | 7DFB6AE11CAEBCC600C2F0D3 /* SwipeTableViewTests */,
302 | );
303 | };
304 | /* End PBXProject section */
305 |
306 | /* Begin PBXResourcesBuildPhase section */
307 | 7DFB6AC71CAEBCC600C2F0D3 /* Resources */ = {
308 | isa = PBXResourcesBuildPhase;
309 | buildActionMask = 2147483647;
310 | files = (
311 | 7D2C2AB01D32A7AD00C6A234 /* onepiece_kiudai.png in Resources */,
312 | 7D2C2AB51D32A7AD00C6A234 /* github.png in Resources */,
313 | 7DFB6ADC1CAEBCC600C2F0D3 /* LaunchScreen.storyboard in Resources */,
314 | 7DFB6AD91CAEBCC600C2F0D3 /* Assets.xcassets in Resources */,
315 | 7DFB6AD71CAEBCC600C2F0D3 /* Main.storyboard in Resources */,
316 | );
317 | runOnlyForDeploymentPostprocessing = 0;
318 | };
319 | 7DFB6AE01CAEBCC600C2F0D3 /* Resources */ = {
320 | isa = PBXResourcesBuildPhase;
321 | buildActionMask = 2147483647;
322 | files = (
323 | );
324 | runOnlyForDeploymentPostprocessing = 0;
325 | };
326 | /* End PBXResourcesBuildPhase section */
327 |
328 | /* Begin PBXSourcesBuildPhase section */
329 | 7DFB6AC51CAEBCC600C2F0D3 /* Sources */ = {
330 | isa = PBXSourcesBuildPhase;
331 | buildActionMask = 2147483647;
332 | files = (
333 | 7DFB6AD11CAEBCC600C2F0D3 /* AppDelegate.m in Sources */,
334 | 7DFB6AF41CAEBCEB00C2F0D3 /* SwipeTableView.m in Sources */,
335 | 7D2C2AB81D32A7AD00C6A234 /* STTransitions.m in Sources */,
336 | 7DFB6AF71CAEBCFA00C2F0D3 /* UIView+STFrame.m in Sources */,
337 | 7D2C2AB61D32A7AD00C6A234 /* STRefreshHeader.m in Sources */,
338 | 7D2C2AB91D32A7AD00C6A234 /* CustomCollectionView.m in Sources */,
339 | 7D2C2AB71D32A7AD00C6A234 /* UIScrollView+STRefresh.m in Sources */,
340 | 7D239A0B1D1D84DB004FF025 /* STHeaderView.m in Sources */,
341 | 7D2C2AB21D32A7AD00C6A234 /* STListController.m in Sources */,
342 | 7D1C83FC1D2416B7001859EB /* STCollectionView.m in Sources */,
343 | 7D2C2ABB1D32A7AD00C6A234 /* CustomTableView.m in Sources */,
344 | 7D2C2ABA1D32A7AD00C6A234 /* CustomSegmentControl.m in Sources */,
345 | 7DFB6ACE1CAEBCC600C2F0D3 /* main.m in Sources */,
346 | 7D2C2AB41D32A7AD00C6A234 /* STViewController.m in Sources */,
347 | 7D2C2AB11D32A7AD00C6A234 /* STImageController.m in Sources */,
348 | );
349 | runOnlyForDeploymentPostprocessing = 0;
350 | };
351 | 7DFB6ADE1CAEBCC600C2F0D3 /* Sources */ = {
352 | isa = PBXSourcesBuildPhase;
353 | buildActionMask = 2147483647;
354 | files = (
355 | 7DFB6AE71CAEBCC600C2F0D3 /* SwipeTableViewTests.m in Sources */,
356 | );
357 | runOnlyForDeploymentPostprocessing = 0;
358 | };
359 | /* End PBXSourcesBuildPhase section */
360 |
361 | /* Begin PBXTargetDependency section */
362 | 7DFB6AE41CAEBCC600C2F0D3 /* PBXTargetDependency */ = {
363 | isa = PBXTargetDependency;
364 | target = 7DFB6AC81CAEBCC600C2F0D3 /* SwipeTableView */;
365 | targetProxy = 7DFB6AE31CAEBCC600C2F0D3 /* PBXContainerItemProxy */;
366 | };
367 | /* End PBXTargetDependency section */
368 |
369 | /* Begin PBXVariantGroup section */
370 | 7DFB6AD51CAEBCC600C2F0D3 /* Main.storyboard */ = {
371 | isa = PBXVariantGroup;
372 | children = (
373 | 7DFB6AD61CAEBCC600C2F0D3 /* Base */,
374 | );
375 | name = Main.storyboard;
376 | sourceTree = "";
377 | };
378 | 7DFB6ADA1CAEBCC600C2F0D3 /* LaunchScreen.storyboard */ = {
379 | isa = PBXVariantGroup;
380 | children = (
381 | 7DFB6ADB1CAEBCC600C2F0D3 /* Base */,
382 | );
383 | name = LaunchScreen.storyboard;
384 | sourceTree = "";
385 | };
386 | /* End PBXVariantGroup section */
387 |
388 | /* Begin XCBuildConfiguration section */
389 | 7DFB6AE91CAEBCC600C2F0D3 /* Debug */ = {
390 | isa = XCBuildConfiguration;
391 | buildSettings = {
392 | ALWAYS_SEARCH_USER_PATHS = NO;
393 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
394 | CLANG_CXX_LIBRARY = "libc++";
395 | CLANG_ENABLE_MODULES = YES;
396 | CLANG_ENABLE_OBJC_ARC = YES;
397 | CLANG_WARN_BOOL_CONVERSION = YES;
398 | CLANG_WARN_CONSTANT_CONVERSION = YES;
399 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
400 | CLANG_WARN_EMPTY_BODY = YES;
401 | CLANG_WARN_ENUM_CONVERSION = YES;
402 | CLANG_WARN_INT_CONVERSION = YES;
403 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
404 | CLANG_WARN_UNREACHABLE_CODE = YES;
405 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
406 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
407 | COPY_PHASE_STRIP = NO;
408 | DEBUG_INFORMATION_FORMAT = dwarf;
409 | ENABLE_STRICT_OBJC_MSGSEND = YES;
410 | ENABLE_TESTABILITY = YES;
411 | GCC_C_LANGUAGE_STANDARD = gnu99;
412 | GCC_DYNAMIC_NO_PIC = NO;
413 | GCC_NO_COMMON_BLOCKS = YES;
414 | GCC_OPTIMIZATION_LEVEL = 0;
415 | GCC_PREPROCESSOR_DEFINITIONS = (
416 | "DEBUG=1",
417 | "$(inherited)",
418 | );
419 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
420 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
421 | GCC_WARN_UNDECLARED_SELECTOR = YES;
422 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
423 | GCC_WARN_UNUSED_FUNCTION = YES;
424 | GCC_WARN_UNUSED_VARIABLE = YES;
425 | IPHONEOS_DEPLOYMENT_TARGET = 9.2;
426 | MTL_ENABLE_DEBUG_INFO = YES;
427 | ONLY_ACTIVE_ARCH = YES;
428 | SDKROOT = iphoneos;
429 | };
430 | name = Debug;
431 | };
432 | 7DFB6AEA1CAEBCC600C2F0D3 /* Release */ = {
433 | isa = XCBuildConfiguration;
434 | buildSettings = {
435 | ALWAYS_SEARCH_USER_PATHS = NO;
436 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
437 | CLANG_CXX_LIBRARY = "libc++";
438 | CLANG_ENABLE_MODULES = YES;
439 | CLANG_ENABLE_OBJC_ARC = YES;
440 | CLANG_WARN_BOOL_CONVERSION = YES;
441 | CLANG_WARN_CONSTANT_CONVERSION = YES;
442 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
443 | CLANG_WARN_EMPTY_BODY = YES;
444 | CLANG_WARN_ENUM_CONVERSION = YES;
445 | CLANG_WARN_INT_CONVERSION = YES;
446 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
447 | CLANG_WARN_UNREACHABLE_CODE = YES;
448 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
449 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
450 | COPY_PHASE_STRIP = NO;
451 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
452 | ENABLE_NS_ASSERTIONS = NO;
453 | ENABLE_STRICT_OBJC_MSGSEND = YES;
454 | GCC_C_LANGUAGE_STANDARD = gnu99;
455 | GCC_NO_COMMON_BLOCKS = YES;
456 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
457 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
458 | GCC_WARN_UNDECLARED_SELECTOR = YES;
459 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
460 | GCC_WARN_UNUSED_FUNCTION = YES;
461 | GCC_WARN_UNUSED_VARIABLE = YES;
462 | IPHONEOS_DEPLOYMENT_TARGET = 9.2;
463 | MTL_ENABLE_DEBUG_INFO = NO;
464 | SDKROOT = iphoneos;
465 | VALIDATE_PRODUCT = YES;
466 | };
467 | name = Release;
468 | };
469 | 7DFB6AEC1CAEBCC600C2F0D3 /* Debug */ = {
470 | isa = XCBuildConfiguration;
471 | buildSettings = {
472 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
473 | DEVELOPMENT_TEAM = 437D87LT4G;
474 | INFOPLIST_FILE = SwipeTableView/Info.plist;
475 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
476 | PRODUCT_BUNDLE_IDENTIFIER = com.roylee.SwipeTableView;
477 | PRODUCT_NAME = "$(TARGET_NAME)";
478 | };
479 | name = Debug;
480 | };
481 | 7DFB6AED1CAEBCC600C2F0D3 /* Release */ = {
482 | isa = XCBuildConfiguration;
483 | buildSettings = {
484 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
485 | DEVELOPMENT_TEAM = 437D87LT4G;
486 | INFOPLIST_FILE = SwipeTableView/Info.plist;
487 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
488 | PRODUCT_BUNDLE_IDENTIFIER = com.roylee.SwipeTableView;
489 | PRODUCT_NAME = "$(TARGET_NAME)";
490 | };
491 | name = Release;
492 | };
493 | 7DFB6AEF1CAEBCC600C2F0D3 /* Debug */ = {
494 | isa = XCBuildConfiguration;
495 | buildSettings = {
496 | BUNDLE_LOADER = "$(TEST_HOST)";
497 | INFOPLIST_FILE = SwipeTableViewTests/Info.plist;
498 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
499 | PRODUCT_BUNDLE_IDENTIFIER = mengliang.SwipeTableViewTests;
500 | PRODUCT_NAME = "$(TARGET_NAME)";
501 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/SwipeTableView.app/SwipeTableView";
502 | };
503 | name = Debug;
504 | };
505 | 7DFB6AF01CAEBCC600C2F0D3 /* Release */ = {
506 | isa = XCBuildConfiguration;
507 | buildSettings = {
508 | BUNDLE_LOADER = "$(TEST_HOST)";
509 | INFOPLIST_FILE = SwipeTableViewTests/Info.plist;
510 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
511 | PRODUCT_BUNDLE_IDENTIFIER = mengliang.SwipeTableViewTests;
512 | PRODUCT_NAME = "$(TARGET_NAME)";
513 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/SwipeTableView.app/SwipeTableView";
514 | };
515 | name = Release;
516 | };
517 | /* End XCBuildConfiguration section */
518 |
519 | /* Begin XCConfigurationList section */
520 | 7DFB6AC41CAEBCC600C2F0D3 /* Build configuration list for PBXProject "SwipeTableView" */ = {
521 | isa = XCConfigurationList;
522 | buildConfigurations = (
523 | 7DFB6AE91CAEBCC600C2F0D3 /* Debug */,
524 | 7DFB6AEA1CAEBCC600C2F0D3 /* Release */,
525 | );
526 | defaultConfigurationIsVisible = 0;
527 | defaultConfigurationName = Release;
528 | };
529 | 7DFB6AEB1CAEBCC600C2F0D3 /* Build configuration list for PBXNativeTarget "SwipeTableView" */ = {
530 | isa = XCConfigurationList;
531 | buildConfigurations = (
532 | 7DFB6AEC1CAEBCC600C2F0D3 /* Debug */,
533 | 7DFB6AED1CAEBCC600C2F0D3 /* Release */,
534 | );
535 | defaultConfigurationIsVisible = 0;
536 | defaultConfigurationName = Release;
537 | };
538 | 7DFB6AEE1CAEBCC600C2F0D3 /* Build configuration list for PBXNativeTarget "SwipeTableViewTests" */ = {
539 | isa = XCConfigurationList;
540 | buildConfigurations = (
541 | 7DFB6AEF1CAEBCC600C2F0D3 /* Debug */,
542 | 7DFB6AF01CAEBCC600C2F0D3 /* Release */,
543 | );
544 | defaultConfigurationIsVisible = 0;
545 | defaultConfigurationName = Release;
546 | };
547 | /* End XCConfigurationList section */
548 | };
549 | rootObject = 7DFB6AC11CAEBCC600C2F0D3 /* Project object */;
550 | }
551 |
--------------------------------------------------------------------------------
/SwipeTableView.xcodeproj/project.xcworkspace/contents.xcworkspacedata:
--------------------------------------------------------------------------------
1 |
2 |
4 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/SwipeTableView.xcodeproj/project.xcworkspace/xcuserdata/roylee.xcuserdatad/UserInterfaceState.xcuserstate:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/liangdrime/SwipeTableView/ffdc47708ca33ee209ae09c9433f71d1463dacc2/SwipeTableView.xcodeproj/project.xcworkspace/xcuserdata/roylee.xcuserdatad/UserInterfaceState.xcuserstate
--------------------------------------------------------------------------------
/SwipeTableView.xcodeproj/xcuserdata/roylee.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
--------------------------------------------------------------------------------
/SwipeTableView.xcodeproj/xcuserdata/roylee.xcuserdatad/xcschemes/SwipeTableView.xcscheme:
--------------------------------------------------------------------------------
1 |
2 |
5 |
8 |
9 |
15 |
21 |
22 |
23 |
24 |
25 |
30 |
31 |
33 |
39 |
40 |
41 |
42 |
43 |
49 |
50 |
51 |
52 |
53 |
54 |
64 |
66 |
72 |
73 |
74 |
75 |
79 |
80 |
81 |
82 |
83 |
84 |
90 |
92 |
98 |
99 |
100 |
101 |
103 |
104 |
107 |
108 |
109 |
--------------------------------------------------------------------------------
/SwipeTableView.xcodeproj/xcuserdata/roylee.xcuserdatad/xcschemes/xcschememanagement.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | SchemeUserState
6 |
7 | SwipeTableView.xcscheme
8 |
9 | orderHint
10 | 0
11 |
12 |
13 | SuppressBuildableAutocreation
14 |
15 | 7DFB6AC81CAEBCC600C2F0D3
16 |
17 | primary
18 |
19 |
20 | 7DFB6AE11CAEBCC600C2F0D3
21 |
22 | primary
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/SwipeTableView/AppDelegate.h:
--------------------------------------------------------------------------------
1 | //
2 | // AppDelegate.h
3 | // SwipeTableView
4 | //
5 | // Created by Roy lee on 16/4/1.
6 | // Copyright © 2016年 Roy lee. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | @interface AppDelegate : UIResponder
12 |
13 | @property (strong, nonatomic) UIWindow *window;
14 |
15 |
16 | @end
17 |
18 |
--------------------------------------------------------------------------------
/SwipeTableView/AppDelegate.m:
--------------------------------------------------------------------------------
1 | //
2 | // AppDelegate.m
3 | // SwipeTableView
4 | //
5 | // Created by Roy lee on 16/4/1.
6 | // Copyright © 2016年 Roy lee. All rights reserved.
7 | //
8 |
9 | #import "AppDelegate.h"
10 |
11 | @interface AppDelegate ()
12 |
13 | @end
14 |
15 | @implementation AppDelegate
16 |
17 |
18 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
19 | // Override point for customization after application launch.
20 | return YES;
21 | }
22 |
23 | - (void)applicationWillResignActive:(UIApplication *)application {
24 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
25 | // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
26 | }
27 |
28 | - (void)applicationDidEnterBackground:(UIApplication *)application {
29 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
30 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
31 | }
32 |
33 | - (void)applicationWillEnterForeground:(UIApplication *)application {
34 | // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
35 | }
36 |
37 | - (void)applicationDidBecomeActive:(UIApplication *)application {
38 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
39 | }
40 |
41 | - (void)applicationWillTerminate:(UIApplication *)application {
42 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
43 | }
44 |
45 | @end
46 |
--------------------------------------------------------------------------------
/SwipeTableView/Assets.xcassets/AppIcon.appiconset/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "images" : [
3 | {
4 | "idiom" : "iphone",
5 | "size" : "29x29",
6 | "scale" : "2x"
7 | },
8 | {
9 | "idiom" : "iphone",
10 | "size" : "29x29",
11 | "scale" : "3x"
12 | },
13 | {
14 | "idiom" : "iphone",
15 | "size" : "40x40",
16 | "scale" : "2x"
17 | },
18 | {
19 | "idiom" : "iphone",
20 | "size" : "40x40",
21 | "scale" : "3x"
22 | },
23 | {
24 | "idiom" : "iphone",
25 | "size" : "60x60",
26 | "scale" : "2x"
27 | },
28 | {
29 | "idiom" : "iphone",
30 | "size" : "60x60",
31 | "scale" : "3x"
32 | }
33 | ],
34 | "info" : {
35 | "version" : 1,
36 | "author" : "xcode"
37 | }
38 | }
--------------------------------------------------------------------------------
/SwipeTableView/Base.lproj/LaunchScreen.storyboard:
--------------------------------------------------------------------------------
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 |
--------------------------------------------------------------------------------
/SwipeTableView/Base.lproj/Main.storyboard:
--------------------------------------------------------------------------------
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 |
--------------------------------------------------------------------------------
/SwipeTableView/Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | en
7 | CFBundleExecutable
8 | $(EXECUTABLE_NAME)
9 | CFBundleIdentifier
10 | $(PRODUCT_BUNDLE_IDENTIFIER)
11 | CFBundleInfoDictionaryVersion
12 | 6.0
13 | CFBundleName
14 | $(PRODUCT_NAME)
15 | CFBundlePackageType
16 | APPL
17 | CFBundleShortVersionString
18 | 1.0
19 | CFBundleSignature
20 | ????
21 | CFBundleVersion
22 | 1
23 | LSRequiresIPhoneOS
24 |
25 | UILaunchStoryboardName
26 | LaunchScreen
27 | UIMainStoryboardFile
28 | Main
29 | UIRequiredDeviceCapabilities
30 |
31 | armv7
32 |
33 | UISupportedInterfaceOrientations
34 |
35 | UIInterfaceOrientationPortrait
36 | UIInterfaceOrientationLandscapeLeft
37 | UIInterfaceOrientationLandscapeRight
38 |
39 |
40 |
41 |
--------------------------------------------------------------------------------
/SwipeTableView/SwipeTableView/STCollectionView.h:
--------------------------------------------------------------------------------
1 | //
2 | // STCollectionView.h
3 | // SwipeTableView
4 | //
5 | // Created by Roy lee on 16/6/29.
6 | // Copyright © 2016年 Roy lee. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 |
12 | @class STCollectionView;
13 | @class STCollectionViewFlowLayout;
14 |
15 | /**
16 | `STCollectionView`数据源,代替`UICollectionViewDataSource`协议.使用注意如下:
17 |
18 | ①.`STCollectionView`及其子类最好不要使用系统的`UICollectionViewDataSource`协议方法,否则在 dataSource 不是 self 的情况下数据展示会不正常(内部的 dataSource 设置始终是 self).
19 | ②.DataDource 需要实现`stCollectionView:numberOfItemsInSection:`与`stCollectionView:cellForItemAtIndexPath:`方法提供数据,此时系统的数据源协议要用此协议方法替换.
20 | */
21 | @protocol STCollectionViewDataSource
22 |
23 | /**
24 | * 以下两个方法提供 collection view 所需数据.
25 | * ①.返回对应 section 的 item 的个数.
26 | * ②.返回对应 indexPath 的 cell.
27 | */
28 | - (NSInteger)stCollectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section;
29 | - (UICollectionViewCell *)stCollectionView:(STCollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath;
30 |
31 | @optional
32 |
33 | /**
34 | * 返回collection view section 的个数.
35 | */
36 | - (NSInteger)numberOfSectionsInStCollectionView:(UICollectionView *)collectionView;
37 |
38 | /**
39 | * 设置 collection view 在 indexPath 下的 SupplementaryElement,可以通过这个方法设置 header 跟 footer.
40 | * 请勿使用原有方法`collectionView:viewForSupplementaryElementOfKind:atIndexPath:`.
41 | */
42 | - (UICollectionReusableView *)stCollectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath;
43 |
44 | @end
45 |
46 |
47 | @protocol STCollectionViewDelegate
48 | @end
49 |
50 |
51 |
52 | /**
53 | SwipeTableView 混合模式下,如果当前的 item 是`UICollectionView`的话,而且在默认支持自适应 contenSize 的条件下,该 item 需要是`STCollectionView`的实例或其子类的实例.
54 |
55 | 对于layout,现在十分方便,已经完成了普通 CollectionView 的布局还有瀑布流支持,只需要调取`st_collectionViewLayout`属性获得`STCollectionViewFlowLayout`的实例,简单设置列数等参数,在不设置`itemHeight`的添加下通过代理提供item的高就可以了.
56 | */
57 | @interface STCollectionView : UICollectionView
58 |
59 | /**
60 | * 设置 collection view 的数据源与代理,遵守`STCollectionViewDataSource` & `UICollectionViewDelegate`协议.
61 | */
62 | @property (nonatomic, weak) idstDataSource;
63 | @property (nonatomic, weak) idstDelegate;
64 |
65 | /**
66 | * 用于设置 collection view 最小要求的 contentSize.
67 | */
68 | @property (nonatomic, assign) CGSize minRequireContentSize;
69 |
70 | /**
71 | * collection view 的 header view,在`SwipeTableView`支持下拉刷新的模式下,用于顶部留白的占位.
72 | */
73 | @property (nonatomic, readonly, strong) UIView * collectionHeadView;
74 |
75 | /**
76 | * 继承自`UICollectionViewFlowLayout`的`STCollectionViewFlowLayout`,是当前 collection view 的 flowlayout.用户可以通过这个属性拿到 collection view 的 flowlayout, 设置一些参数进行简单布局.
77 | */
78 | @property (nonatomic, readonly, strong) STCollectionViewFlowLayout * st_collectionViewLayout;
79 |
80 |
81 | /**
82 | * 默认初始化方法,可以不用传入 layout 参数.
83 | */
84 | - (instancetype)initWithFrame:(CGRect)frame NS_DESIGNATED_INITIALIZER;
85 | - (instancetype)initWithCoder:(NSCoder *)aDecoder NS_DESIGNATED_INITIALIZER;
86 |
87 | @end
88 |
89 |
90 |
91 |
92 | /**
93 | `STCollectionViewFlowLayout`数据源,可以实现`STCollectionView:layout:heightForItemAtIndexPath:`来动态设置 item 的高度.
94 | */
95 | @protocol STCollectionViewFlowLayoutDelegate
96 |
97 | @required
98 | /**
99 | * 返回 section 所在区的列数.
100 | */
101 | - (NSInteger)collectionView:(UICollectionView *)collectionView
102 | layout:(STCollectionViewFlowLayout *)layout
103 | numberOfColumnsInSection:(NSInteger)section;
104 |
105 | @end
106 |
107 | /**
108 | `STCollectionView`专用的 flowlayout,用户需要获取`STCollectionView`的`STCollectionViewFlowLayout`来设置参数进行布局.
109 |
110 | 现功能可以支持普通 collection view 布局 & 瀑布流布局.
111 | 用户自定义 flowlayout 需要继承自`STCollectionViewFlowLayout`,并且要在重写`prepareLayout`,`layoutAttributesForElementsInRect`与`collectionViewContentSize`方法的时候调用父类的方法.
112 | 例如:
113 | - (void)prepareLayout {
114 | [super prepareLayout];
115 | // do something in sub class......
116 | }
117 |
118 | - (NSArray *)layoutAttributesForElementsInRect:(CGRect)rect {
119 | NSArray * superAttrs = [super layoutAttributesForElementsInRect:rect];
120 | NSMutableArray * itemAttrs = [superAttrs mutableCopy];
121 |
122 | // filter subClassAttrs to rect
123 | NSArray * filteredSubClassAttrs = ........;
124 |
125 | [itemAttrs addObjectsFromArray:fittesSubClassAttrs];
126 |
127 | return itemAttrs;
128 | }
129 |
130 | - (CGSize)collectionViewContentSize {
131 | CGSize superSize = [super collectionViewContentSize];
132 |
133 | CGSize subClassSize = .......;
134 | subClassSize.height += superSize.height;
135 |
136 | // fit mincontentSize
137 | STCollectionView * collectionView = (STCollectionView *)self.collectionView;
138 | subClassSize.height = fmax(subClassSize.height, collectionView.minRequireContentSize.height);
139 |
140 | return subClassSize;
141 | }
142 |
143 | */
144 | @interface STCollectionViewFlowLayout : UICollectionViewFlowLayout
145 |
146 | @property (nonatomic, assign) CGFloat columnCount;
147 | @property (nonatomic, assign) CGFloat minimumLineSpacing;
148 | @property (nonatomic, assign) CGFloat minimumInteritemSpacing;
149 | @property (nonatomic, assign) UIEdgeInsets sectionInset;
150 | @property (nonatomic, assign) CGSize itemSize;
151 |
152 | /**
153 | * 需要自定义 flowlayout 的时候,自定义的 flowlayout 需要继承自`STCollectionViewFlowLayout`,并且在布局 Attributes 的时候,第一个 Attributes 的 orgin.y 需要从`topOffsetOfFirstAttributes`开始,而不是0点的位置
154 | */
155 | @property (nonatomic, readonly, assign) CGFloat topOffsetOfFirstAttributes;
156 |
157 | @end
158 |
159 |
160 |
161 |
162 |
163 |
164 |
165 |
166 |
167 |
168 |
--------------------------------------------------------------------------------
/SwipeTableView/SwipeTableView/STCollectionView.m:
--------------------------------------------------------------------------------
1 | //
2 | // STCollectionView.m
3 | // SwipeTableView
4 | //
5 | // Created by Roy lee on 16/6/29.
6 | // Copyright © 2016年 Roy lee. All rights reserved.
7 | //
8 |
9 | #import "STCollectionView.h"
10 | #import "SwipeTableView.h"
11 |
12 | NSString *const STCollectionElementKindSectionHeader = @"STCollectionElementKindSectionHeader";
13 | NSString *const STCollectionHeaderIdfy = @"STCollectionHeaderIdfy";
14 |
15 |
16 | @interface STCollectionView ()
17 |
18 | @property (nonatomic, strong) UIView * collectionHeadView;
19 | @property (nonatomic, strong) STCollectionViewFlowLayout * st_collectionViewLayout;
20 |
21 | @end
22 |
23 |
24 | @implementation STCollectionView
25 |
26 | - (instancetype)initWithFrame:(CGRect)frame {
27 | STCollectionViewFlowLayout * flowLayout = [[STCollectionViewFlowLayout alloc]init];
28 | self = [super initWithFrame:frame collectionViewLayout:flowLayout];
29 | if (self) {
30 | [self registerClass:UICollectionReusableView.class forSupplementaryViewOfKind:STCollectionElementKindSectionHeader withReuseIdentifier:STCollectionHeaderIdfy];
31 | [self setDataSource:self];
32 | [self setDelegate:self];
33 | }
34 | return self;
35 | }
36 |
37 | - (instancetype)initWithCoder:(NSCoder *)aDecoder {
38 | self = [super initWithCoder:aDecoder];
39 | if (self) {
40 | STCollectionViewFlowLayout * flowLayout = [[STCollectionViewFlowLayout alloc]init];
41 | self.collectionViewLayout = flowLayout;
42 | [self registerClass:UICollectionReusableView.class forSupplementaryViewOfKind:STCollectionElementKindSectionHeader withReuseIdentifier:STCollectionHeaderIdfy];
43 | [self setDataSource:self];
44 | [self setDelegate:self];
45 | }
46 | return self;
47 | }
48 |
49 | - (instancetype)initWithFrame:(CGRect)frame collectionViewLayout:(UICollectionViewLayout *)layout {
50 | self = [self initWithFrame:frame];
51 | if (!self) {
52 | return nil;
53 | }
54 | return self;
55 | }
56 |
57 | - (STCollectionViewFlowLayout *)st_collectionViewLayout {
58 | return (STCollectionViewFlowLayout *)self.collectionViewLayout;
59 | }
60 |
61 | - (void)setCollectionViewLayout:(STCollectionViewFlowLayout *)collectionViewLayout {
62 | NSAssert([collectionViewLayout isKindOfClass:STCollectionViewFlowLayout.class], @"collectionViewLayout must be class of STCollectionViewFlowLayout or subclass of STCollectionViewFlowLayout ");
63 | [super setCollectionViewLayout:collectionViewLayout];
64 | }
65 |
66 | #pragma mark - UICollectionViewDataSource & UICollectionViewDelegateFlowLayout
67 |
68 | // header view
69 | - (UICollectionReusableView *)collectionView:(STCollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath {
70 |
71 | UICollectionReusableView * headerView = nil;
72 | if (kind == STCollectionElementKindSectionHeader) {
73 | headerView = [collectionView dequeueReusableSupplementaryViewOfKind:STCollectionElementKindSectionHeader withReuseIdentifier:STCollectionHeaderIdfy forIndexPath:indexPath];
74 | if (nil != _collectionHeadView) {
75 | headerView.frame = _collectionHeadView.bounds;
76 | [headerView addSubview:_collectionHeadView];
77 | }
78 | }else {
79 | if (self.stDataSource && [self.stDataSource respondsToSelector:@selector(stCollectionView:viewForSupplementaryElementOfKind:atIndexPath:)]) {
80 | headerView = [self.stDataSource stCollectionView:collectionView viewForSupplementaryElementOfKind:kind atIndexPath:indexPath];
81 | }
82 | }
83 | return headerView;
84 | }
85 |
86 | // override methods below by subclass
87 | - (NSInteger)numberOfSectionsInCollectionView:(STCollectionView *)collectionView {
88 | NSInteger sectionNum = 1;
89 | if (self.stDataSource && [_stDataSource respondsToSelector:@selector(numberOfSectionsInStCollectionView:)]) {
90 | sectionNum = [_stDataSource numberOfSectionsInStCollectionView:collectionView];
91 | }
92 | return fmax(1, sectionNum);
93 | }
94 |
95 | - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
96 | NSInteger itemNum = 0;
97 | if (self.stDataSource && [_stDataSource respondsToSelector:@selector(stCollectionView:numberOfItemsInSection:)]) {
98 | itemNum = [_stDataSource stCollectionView:collectionView numberOfItemsInSection:section];
99 | }
100 | return itemNum;
101 | }
102 |
103 | - (UICollectionViewCell *)collectionView:(STCollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
104 | UICollectionViewCell * cell = nil;
105 | if (_stDataSource && [_stDataSource respondsToSelector:@selector(stCollectionView:cellForItemAtIndexPath:)]) {
106 | cell = [_stDataSource stCollectionView:collectionView cellForItemAtIndexPath:indexPath];
107 | }
108 | return cell;
109 | }
110 |
111 | #pragma mark - Setter
112 | /**
113 | * override to setter methods to associate `STCollectionViewFlowLayoutDelegate` & `STCollectionViewDataSource`
114 | */
115 | - (void)setDelegate:(id)delegate {
116 | [super setDelegate:delegate];
117 | }
118 |
119 | - (void)setDataSource:(id)dataSource {
120 | [super setDataSource:self];
121 | self.stDataSource = (id)dataSource;
122 | }
123 |
124 | - (void)setMinRequireContentSize:(CGSize)minRequireContentSize {
125 | _minRequireContentSize = minRequireContentSize;
126 | [self.st_collectionViewLayout invalidateLayout];
127 |
128 | }
129 |
130 |
131 | @end
132 |
133 |
134 |
135 | @interface STCollectionViewFlowLayout ()
136 |
137 | /**
138 | * 在支持下拉刷新状态下,顶部留白 header 的 attributes & height
139 | */
140 | @property (nonatomic, strong) UICollectionViewLayoutAttributes * headerAttributes;
141 | @property (nonatomic, assign) CGFloat headerHeight;
142 |
143 | /**
144 | * 存储每个区的 rect.
145 | */
146 | @property (nonatomic, strong) NSMutableArray * sectionRects;
147 |
148 | /**
149 | * 字典形式存储每个区的所有列的所有 item 的 rect.
150 | * 结构是:每个区的数据 section 为 key,存储所有列中所有 item 的 rect 的大数组作为 value, 大数组存放与列数相同个数的数组,每个小数组存放对应列的的所有 items 的 rect.
151 | */
152 | @property (nonatomic, strong) NSMutableDictionary * columnRectsInSection;
153 |
154 | /**
155 | * 所有 items 的 attributes.
156 | */
157 | @property (nonatomic, strong) NSMutableDictionary * layoutItemAttributes;
158 |
159 | /**
160 | * 存储所有 header 与 footer 的 attributes.
161 | */
162 | @property (nonatomic, strong) NSDictionary * headerFooterItemAttributes;
163 |
164 | @end
165 |
166 |
167 | @implementation STCollectionViewFlowLayout
168 | @synthesize minimumLineSpacing = _minimumLineSpacing;
169 | @synthesize minimumInteritemSpacing = _minimumInteritemSpacing;
170 | @synthesize itemSize = _itemSize;
171 | @synthesize sectionInset = _sectionInset;
172 |
173 | // 判断当前 layout 是不是自定义的子类
174 | BOOL isSubClass(STCollectionViewFlowLayout * self) {
175 | if (![self isMemberOfClass:STCollectionViewFlowLayout.class]) {
176 | return YES;
177 | }
178 | return NO;
179 | }
180 |
181 | - (void)prepareLayout {
182 |
183 | NSUInteger numberOfSections = self.collectionView.numberOfSections;
184 | self.sectionRects = [[NSMutableArray alloc] initWithCapacity:numberOfSections];
185 | self.columnRectsInSection = [[NSMutableDictionary alloc] initWithCapacity:numberOfSections];
186 | self.layoutItemAttributes = [[NSMutableDictionary alloc] initWithCapacity:numberOfSections];
187 | self.headerFooterItemAttributes = @{UICollectionElementKindSectionHeader:[NSMutableArray array],
188 | UICollectionElementKindSectionFooter:[NSMutableArray array]};
189 |
190 | // Creat top palceholder header attributes.
191 | [self calculateTopHeaderAttributes];
192 | // If self is subclass of STCollectionViewFlowLayout class,return after creat top header.
193 | if (isSubClass(self)) {
194 | return;
195 | }
196 | for (NSUInteger section = 0; section < numberOfSections; section ++) {
197 | NSUInteger itemsInSection = [self.collectionView numberOfItemsInSection:section];
198 | [self.layoutItemAttributes setObject:[NSMutableArray array] forKey:@(section)];
199 | [self prepareLayoutInSection:section numberOfItems:itemsInSection];
200 | }
201 | }
202 |
203 | - (UICollectionViewLayoutAttributes *)layoutAttributesForSupplementaryViewOfKind:(NSString *)kind
204 | atIndexPath:(NSIndexPath *)indexPath {
205 | if ([kind isEqualToString:STCollectionElementKindSectionHeader]) {
206 | return self.headerAttributes;
207 | }
208 | return self.headerFooterItemAttributes[kind][indexPath.section];
209 | }
210 |
211 | - (UICollectionViewLayoutAttributes *)layoutAttributesForItemAtIndexPath:(NSIndexPath *)indexPath {
212 | return self.layoutItemAttributes[@(indexPath.section)][indexPath.item];
213 | }
214 |
215 | - (NSArray *)layoutAttributesForElementsInRect:(CGRect)rect {
216 | if (isSubClass(self)) {
217 | if (CGRectContainsRect(rect, _headerAttributes.frame)) {
218 | return @[_headerAttributes];
219 | }
220 | return @[];
221 | }
222 | return [self searchVisibleLayoutAttributesInRect:rect];
223 | }
224 |
225 | - (CGSize)collectionViewContentSize {
226 | // update contentSize in super layout.
227 | [super collectionViewContentSize];
228 |
229 | if (isSubClass(self)) {
230 | CGSize contentSize = CGSizeMake(CGRectGetWidth(self.collectionView.bounds), _headerHeight);
231 | return contentSize;
232 | }
233 |
234 | CGRect lastSectionRect = [[self.sectionRects lastObject] CGRectValue];
235 | CGSize contentSize = CGSizeMake(CGRectGetWidth(self.collectionView.bounds), CGRectGetMaxY(lastSectionRect));
236 | // fit mincontentSize
237 | STCollectionView * collectionView = (STCollectionView *)self.collectionView;
238 | contentSize.width = fmax(contentSize.width, collectionView.minRequireContentSize.width);
239 | contentSize.height = fmax(contentSize.height, collectionView.minRequireContentSize.height);
240 |
241 | return contentSize;
242 | }
243 |
244 | - (BOOL)shouldInvalidateLayoutForBoundsChange:(CGRect)newBounds {
245 | CGRect oldBounds = self.collectionView.bounds;
246 | if (CGRectGetWidth(newBounds) != CGRectGetWidth(oldBounds)) {
247 | return YES;
248 | }
249 | return NO;
250 | }
251 |
252 |
253 | #pragma mark - Privated
254 | - (void)calculateTopHeaderAttributes {
255 | STCollectionView * collectionView = (STCollectionView *)self.collectionView;
256 | NSIndexPath * sectionIndexPath = [NSIndexPath indexPathForItem:0 inSection:0];
257 |
258 | self.headerHeight = 0.0f;
259 | if(nil != collectionView.collectionHeadView) {
260 |
261 | // Initialize the header rectangles.
262 | CGRect headerFrame;
263 | headerFrame.origin.x = 0.0f;
264 | headerFrame.origin.y = 0.0f;
265 |
266 | CGSize headerSize = collectionView.collectionHeadView.bounds.size;
267 | headerFrame.size.height = headerSize.height;
268 | headerFrame.size.width = headerSize.width;
269 |
270 | UICollectionViewLayoutAttributes * headerAttributes = [UICollectionViewLayoutAttributes layoutAttributesForSupplementaryViewOfKind:STCollectionElementKindSectionHeader withIndexPath:sectionIndexPath];
271 | headerAttributes.frame = headerFrame;
272 |
273 | _headerHeight = headerFrame.size.height;
274 | self.headerAttributes = headerAttributes;
275 | }
276 | }
277 |
278 | - (void)prepareLayoutInSection:(NSUInteger)section numberOfItems:(NSUInteger)items {
279 |
280 | STCollectionView * collectionView = (STCollectionView *)self.collectionView;
281 | NSIndexPath * indexPath = [NSIndexPath indexPathForItem:0 inSection:section];
282 |
283 | /** Get the rectangles of last section. */
284 | CGRect previousSectionRect = [self rectForSectionAtIndex:indexPath.section - 1];
285 | CGRect sectionRect;
286 | sectionRect.origin.x = 0;
287 | sectionRect.origin.y = CGRectGetHeight(previousSectionRect) + CGRectGetMinY(previousSectionRect);
288 | sectionRect.size.width = collectionView.bounds.size.width;
289 |
290 | /** Section Header */
291 | id delegate = collectionView.stDelegate;
292 |
293 | CGFloat headerHeight = 0.0f;
294 | if([delegate respondsToSelector:@selector(collectionView:layout:referenceSizeForHeaderInSection:)]) {
295 |
296 | // Initialize the header rectangles.
297 | CGRect headerFrame;
298 | headerFrame.origin.x = 0.0f;
299 | headerFrame.origin.y = sectionRect.origin.y;
300 |
301 | CGSize headerSize = [delegate collectionView:self.collectionView layout:self referenceSizeForHeaderInSection:indexPath.section];
302 | headerFrame.size.height = headerSize.height;
303 | headerFrame.size.width = headerSize.width;
304 |
305 | UICollectionViewLayoutAttributes *headerAttributes =
306 | [UICollectionViewLayoutAttributes layoutAttributesForSupplementaryViewOfKind:UICollectionElementKindSectionHeader withIndexPath:indexPath];
307 | headerAttributes.frame = headerFrame;
308 |
309 | headerHeight = headerFrame.size.height;
310 | [self.headerFooterItemAttributes[UICollectionElementKindSectionHeader] addObject:headerAttributes];
311 | }
312 |
313 | /** Items In Section. */
314 | UIEdgeInsets sectionInsets = self.sectionInset;
315 | if([delegate respondsToSelector:@selector(collectionView:layout:insetForSectionAtIndex:)]) {
316 | sectionInsets = [delegate collectionView:collectionView layout:self insetForSectionAtIndex:section];
317 | }
318 |
319 | // Set the lineSpacing & interitemSpacing between the items, default values is 0.0f.
320 | CGFloat lineSpacing = self.minimumLineSpacing;
321 | CGFloat interitemSpacing = self.minimumInteritemSpacing;
322 |
323 | if ([delegate respondsToSelector:@selector(collectionView:layout:minimumInteritemSpacingForSectionAtIndex:)]) {
324 | interitemSpacing = [delegate collectionView:collectionView layout:self minimumInteritemSpacingForSectionAtIndex:section];
325 | }
326 | if ([delegate respondsToSelector:@selector(collectionView:layout:minimumLineSpacingForSectionAtIndex:)]) {
327 | lineSpacing = [delegate collectionView:collectionView layout:self minimumLineSpacingForSectionAtIndex:section];
328 | }
329 |
330 | // All the items' rectangles in the section
331 | CGRect itemsContentRect;
332 | itemsContentRect.origin.x = sectionInsets.left;
333 | itemsContentRect.origin.y = headerHeight + sectionInsets.top;
334 |
335 | NSAssert(nil != delegate && [delegate respondsToSelector:@selector(collectionView:layout:numberOfColumnsInSection:)], @"The stDelegate of STCollectionView must implementation method `collectionView:layout:numberOfColumnsInSection:`");
336 | NSUInteger numberOfColumns = [delegate collectionView:collectionView layout:self numberOfColumnsInSection:section];
337 | itemsContentRect.size.width = CGRectGetWidth(collectionView.bounds) - (sectionInsets.left + sectionInsets.right);
338 |
339 | CGFloat columnSpace = itemsContentRect.size.width - (interitemSpacing * (numberOfColumns - 1));
340 | CGFloat columnWidth = (columnSpace/numberOfColumns);
341 |
342 | // Initialize an empty mutable array earch column.
343 | NSMutableArray * columnRects = [NSMutableArray arrayWithCapacity:numberOfColumns];
344 | for (NSUInteger coluIndex = 0; coluIndex < numberOfColumns; coluIndex ++) {
345 | [columnRects addObject:[NSMutableArray array]];
346 | }
347 | [self.columnRectsInSection setObject:columnRects forKey:@(section)];
348 |
349 | // Calculate every item's rectangles.
350 | for (NSInteger itemIndex = 0; itemIndex < items; itemIndex ++) {
351 | // Get the possion of the shortest column in the section, it's preferred
352 | NSIndexPath * itemIndexPath = [NSIndexPath indexPathForItem:itemIndex inSection:section];
353 | NSInteger destColumnIdx = [self shortestColumnIndexInSection:section];
354 | NSInteger destRowInColumn = [self numberOfItemsForColumn:destColumnIdx inSection:section];
355 | CGFloat lastItemInColumnMaxY = [self lastItemMaxYForColumn:destColumnIdx inSection:section];
356 |
357 | // First item in column
358 | if (destRowInColumn == 0) {
359 | lastItemInColumnMaxY += sectionRect.origin.y;
360 | }
361 |
362 | // Default item's rectangles is a square.
363 | CGRect itemRect;
364 | itemRect.origin.x = itemsContentRect.origin.x + destColumnIdx * (interitemSpacing + columnWidth);
365 | itemRect.origin.y = lastItemInColumnMaxY + (destRowInColumn > 0 ? lineSpacing: sectionInsets.top);
366 | itemRect.size.width = columnWidth;
367 | itemRect.size.height = columnWidth;
368 |
369 | if (self.itemSize.height > 0) {
370 | itemRect.size.height = _itemSize.height;
371 | }
372 | // Check the flow layout if implementation the `collectionView:layout:sizeForItemAtIndexPath:` protocol methods. If implementation set the itemRect size's height is the protocol return size's height.
373 | if ([delegate respondsToSelector:@selector(collectionView:layout:sizeForItemAtIndexPath:)]) {
374 | CGSize itemSize = [delegate collectionView:collectionView layout:self sizeForItemAtIndexPath:itemIndexPath];
375 | itemRect.size.height = itemSize.height;
376 | }
377 | UICollectionViewLayoutAttributes * itemAttributes = [UICollectionViewLayoutAttributes layoutAttributesForCellWithIndexPath:itemIndexPath];
378 | itemAttributes.frame = itemRect;
379 | [self.layoutItemAttributes[@(section)] addObject:itemAttributes];
380 | [self.columnRectsInSection[@(section)][destColumnIdx] addObject:[NSValue valueWithCGRect:itemRect]];
381 | }
382 |
383 | itemsContentRect.size.height = [self heightOfItemsContentInSection:section];
384 |
385 | /* Section Footer */
386 | CGFloat footerHeight = 0.0f;
387 | if ([delegate respondsToSelector:@selector(collectionView:layout:referenceSizeForFooterInSection:)]) {
388 | CGRect footerFrame;
389 | footerFrame.origin.x = 0;
390 | footerFrame.origin.y = sectionRect.origin.y + headerHeight + itemsContentRect.size.height + (sectionInsets.top + sectionInsets.bottom);
391 |
392 | CGSize footerSize = [delegate collectionView:self.collectionView layout:self referenceSizeForFooterInSection:indexPath.section];
393 | footerFrame.size.height = footerSize.height;
394 | footerFrame.size.width = footerSize.width;
395 |
396 | UICollectionViewLayoutAttributes *footerAttributes = [UICollectionViewLayoutAttributes layoutAttributesForSupplementaryViewOfKind:UICollectionElementKindSectionFooter withIndexPath:indexPath];
397 | footerAttributes.frame = footerFrame;
398 |
399 | footerHeight = footerFrame.size.height;
400 |
401 | [self.headerFooterItemAttributes[UICollectionElementKindSectionFooter] addObject:footerAttributes];
402 | }
403 |
404 | sectionRect.size.height = itemsContentRect.size.height + (headerHeight + footerHeight) + (sectionInsets.top + sectionInsets.bottom);
405 |
406 | [self.sectionRects addObject:[NSValue valueWithCGRect:sectionRect]];
407 | }
408 |
409 | - (CGFloat)heightOfItemsContentInSection:(NSUInteger)sectionIdx {
410 | CGFloat maxHeight = 0.0f;
411 | NSArray * columnsInSection = self.columnRectsInSection[@(sectionIdx)];
412 | for (NSUInteger columnIdx = 0; columnIdx < columnsInSection.count; columnIdx ++) {
413 | if (columnsInSection.count > 0) {
414 | CGFloat heightOfColumn = CGRectGetMaxY([[columnsInSection[columnIdx] lastObject] CGRectValue]);
415 | heightOfColumn -= CGRectGetMinY([[columnsInSection[columnIdx] firstObject] CGRectValue]);
416 | maxHeight = MAX(maxHeight, heightOfColumn);
417 | }
418 | }
419 | return maxHeight;
420 | }
421 |
422 | - (NSInteger)numberOfItemsForColumn:(NSInteger)columnIdx inSection:(NSInteger)sectionIdx {
423 | return [self.columnRectsInSection[@(sectionIdx)][columnIdx] count];
424 | }
425 |
426 | - (CGFloat)lastItemMaxYForColumn:(NSInteger)columnIdx inSection:(NSInteger)sectionIdx {
427 | NSArray * itemsInColumn = self.columnRectsInSection[@(sectionIdx)][columnIdx];
428 | if (itemsInColumn.count == 0) {
429 | if([self.headerFooterItemAttributes[UICollectionElementKindSectionHeader] count] > sectionIdx) {
430 | CGRect headerFrame = [self.headerFooterItemAttributes[UICollectionElementKindSectionHeader][sectionIdx] frame];
431 | return headerFrame.size.height;
432 | }
433 | return 0.0f;
434 | } else {
435 | CGRect lastItemRect = [[itemsInColumn lastObject] CGRectValue];
436 | return CGRectGetMaxY(lastItemRect);
437 | }
438 | }
439 |
440 | // Get the shortest column cell index in the section. It's preferred which cell is shortest column height.
441 | - (NSInteger)shortestColumnIndexInSection:(NSInteger)sectionIdx {
442 | NSUInteger shortestColumnIdx = 0;
443 | CGFloat heightOfShortestColumn = CGFLOAT_MAX;
444 | NSInteger columnCount = [self.columnRectsInSection[@(sectionIdx)] count];
445 | for (NSUInteger columnIdx = 0; columnIdx < columnCount; columnIdx ++) {
446 | CGFloat columnHeight = [self lastItemMaxYForColumn:columnIdx inSection:sectionIdx];
447 | if (columnHeight < heightOfShortestColumn) {
448 | shortestColumnIdx = columnIdx;
449 | heightOfShortestColumn = columnHeight;
450 | }
451 | }
452 | return shortestColumnIdx;
453 | }
454 |
455 | // Get the rectangles of the section.
456 | - (CGRect)rectForSectionAtIndex:(NSInteger)sectionIdx {
457 | if (sectionIdx < 0) {
458 | // Leave the placeholder header height
459 | return (CGRect){0, _headerHeight, 0, 0};
460 | }else if (sectionIdx > self.sectionRects.count - 1) {
461 | return CGRectZero;
462 | }
463 | return [self.sectionRects[sectionIdx] CGRectValue];
464 | }
465 |
466 | #pragma mark - Show Attributes Methods
467 | // Get the visible cells's layout attributes in collectionView's visible rectangles on the screen.
468 | - (NSArray *)searchVisibleLayoutAttributesInRect:(CGRect)rect {
469 | NSMutableArray * itemAttrs = [[NSMutableArray alloc] init];
470 | // Check placeholder header
471 | if (_headerAttributes && CGRectContainsRect(rect, self.headerAttributes.frame)) {
472 | [itemAttrs addObject:self.headerAttributes];
473 | }
474 | // Other attributes
475 | NSIndexSet * visibleSections = [self sectionIndexesInRect:rect];
476 | [visibleSections enumerateIndexesUsingBlock:^(NSUInteger sectionIdx, BOOL *stop) {
477 |
478 | // Check item layout attributes's rectangles if intersectes the collectionView's rectangles.
479 | for (UICollectionViewLayoutAttributes * itemAttr in self.layoutItemAttributes[@(sectionIdx)]) {
480 | CGRect itemRect = itemAttr.frame;
481 | itemAttr.zIndex = 1;
482 | BOOL isVisible = CGRectIntersectsRect(rect, itemRect);
483 | if (isVisible) {
484 | [itemAttrs addObject:itemAttr];
485 | }
486 | }
487 |
488 | // Check footer layout attributes's rectangles if intersectes the collectionView's rectangles.
489 | if ([self.headerFooterItemAttributes[UICollectionElementKindSectionFooter] count] > sectionIdx) {
490 | UICollectionViewLayoutAttributes * footerAttribute = self.headerFooterItemAttributes[UICollectionElementKindSectionFooter][sectionIdx];
491 | BOOL isVisible = CGRectIntersectsRect(rect, footerAttribute.frame);
492 | if (isVisible && footerAttribute) {
493 | [itemAttrs addObject:footerAttribute];
494 | }
495 | }
496 |
497 | // Check header layout attributes's rectangles if intersectes the collectionView's rectangles.
498 | if([self.headerFooterItemAttributes[UICollectionElementKindSectionHeader] count] > sectionIdx) {
499 | UICollectionViewLayoutAttributes *headerAttribute = self.headerFooterItemAttributes[UICollectionElementKindSectionHeader][sectionIdx];
500 |
501 | BOOL isVisibleHeader = CGRectIntersectsRect(rect, headerAttribute.frame);
502 |
503 | if (isVisibleHeader && headerAttribute) {
504 | [itemAttrs addObject:headerAttribute];
505 | }
506 | }
507 | }];
508 | return itemAttrs;
509 | }
510 |
511 | // Get the indexes of section in collectionView's visible rectangles on the screen.
512 | - (NSIndexSet *)sectionIndexesInRect:(CGRect)rect {
513 | CGRect theRect = rect;
514 | NSMutableIndexSet * visibleIndexes = [[NSMutableIndexSet alloc] init];
515 | NSUInteger numberOfSections = self.collectionView.numberOfSections;
516 | for (NSUInteger sectionIdx = 0; sectionIdx < numberOfSections; sectionIdx ++) {
517 | CGRect sectionRect = [self.sectionRects[sectionIdx] CGRectValue];
518 | BOOL isVisible = CGRectIntersectsRect(theRect, sectionRect);
519 | if (isVisible)
520 | [visibleIndexes addIndex:sectionIdx];
521 | }
522 | return visibleIndexes;
523 | }
524 |
525 |
526 | @end
527 |
528 |
529 |
530 |
--------------------------------------------------------------------------------
/SwipeTableView/SwipeTableView/STHeaderView.h:
--------------------------------------------------------------------------------
1 | //
2 | // STHeaderView.h
3 | // SwipeTableView
4 | //
5 | // Created by Roy lee on 16/6/24.
6 | // Copyright © 2016年 Roy lee. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | @class STHeaderView;
12 | @protocol STHeaderViewDelegate
13 |
14 | - (CGPoint)minHeaderViewFrameOrgin;
15 | - (CGPoint)maxHeaderViewFrameOrgin;
16 |
17 | @optional
18 | - (void)headerViewDidFrameChanged:(STHeaderView *)headerView;
19 | - (void)headerView:(STHeaderView *)headerView didPan:(UIPanGestureRecognizer *)pan;
20 | - (void)headerView:(STHeaderView *)headerView didPanGestureRecognizerStateChanged:(UIPanGestureRecognizer *)pan;
21 |
22 | @end
23 |
24 |
25 | /**
26 | 采用 UIKitDynamics 实现自定的 swipeHeaderView
27 |
28 | 只有当`SwipeTableView`的 swipeHeaderView 是`STHeaderView`或其子类的实例,拖拽`SwipeTableView`的 swipeHeaderView才能 同时滚动`SwipeTableView`的 currentItemView.
29 | */
30 | NS_CLASS_AVAILABLE_IOS(7_0) @interface STHeaderView : UIView
31 |
32 | @property (nonatomic, readonly, strong) UIPanGestureRecognizer * panGestureRecognizer;
33 | @property (nonatomic, weak) id delegate;
34 | @property (nonatomic, readonly, getter=isTracking) BOOL tracking;
35 | @property (nonatomic, readonly, getter=isDragging) BOOL dragging;
36 | @property (nonatomic, readonly, getter=isDecelerating) BOOL decelerating;
37 |
38 | /**
39 | * 结束视图的 惯性减速 & 弹性回弹 等效果
40 | */
41 | - (void)endDecelerating;
42 |
43 | @end
44 |
--------------------------------------------------------------------------------
/SwipeTableView/SwipeTableView/STHeaderView.m:
--------------------------------------------------------------------------------
1 | //
2 | // STHeaderView.m
3 | // SwipeTableView
4 | //
5 | // Created by Roy lee on 16/6/24.
6 | // Copyright © 2016年 Roy lee. All rights reserved.
7 | //
8 |
9 | #import "STHeaderView.h"
10 | #import "SwipeTableView.h"
11 |
12 | static CGFloat rubberBandRate(CGFloat offset) {
13 |
14 | const CGFloat constant = 0.15f;
15 | const CGFloat dimension = 10.0f;
16 | const CGFloat startRate = 0.85f;
17 | // 计算拖动视图translation的增量比率,起始值为startRate(此时offset为0);随着frame超出的距离offset的增大,增量比率减小
18 | CGFloat result = dimension * startRate / (dimension + constant * fabs(offset));
19 | return result;
20 | }
21 |
22 | @interface STDynamicItem : NSObject
23 |
24 | @property (nonatomic, readwrite) CGPoint center;
25 | @property (nonatomic, readonly) CGRect bounds;
26 | @property (nonatomic, readwrite) CGAffineTransform transform;
27 |
28 | @end
29 |
30 | @implementation STDynamicItem
31 |
32 | - (instancetype)init {
33 | self = [super init];
34 | if (self) {
35 | // Sets non-zero `bounds`, because otherwise Dynamics throws an exception.
36 | _bounds = CGRectMake(0, 0, 1, 1);
37 | }
38 | return self;
39 | }
40 |
41 | @end
42 |
43 |
44 |
45 |
46 | @interface STHeaderView ()
47 |
48 | @property (nonatomic, strong) UIPanGestureRecognizer * panGestureRecognizer;
49 | @property (nonatomic, strong) UIDynamicAnimator * animator;
50 | @property (nonatomic, strong) UIDynamicItemBehavior * decelerationBehavior;
51 | @property (nonatomic, strong) UIAttachmentBehavior * springBehavior;
52 | @property (nonatomic, strong) STDynamicItem *dynamicItem;
53 | @property (nonatomic, assign) CGRect newFrame;
54 | @property (nonatomic, assign) BOOL tracking;
55 | @property (nonatomic, assign) BOOL dragging;
56 | @property (nonatomic, assign) BOOL decelerating;
57 |
58 | @end
59 |
60 | static void * STHeaderViewPanGestureRecognizerStateContext = &STHeaderViewPanGestureRecognizerStateContext;
61 |
62 | @implementation STHeaderView
63 |
64 | - (void)dealloc {
65 | [self.panGestureRecognizer removeObserver:self forKeyPath:@"state"];
66 | }
67 |
68 | - (instancetype)initWithFrame:(CGRect)frame {
69 | self = [super initWithFrame:frame];
70 | if (self) {
71 | [self commonInit];
72 | }
73 | return self;
74 | }
75 |
76 | - (instancetype)initWithCoder:(NSCoder *)aDecoder {
77 | self = [super initWithCoder:aDecoder];
78 | if (self) {
79 | [self commonInit];
80 | }
81 | return self;
82 | }
83 |
84 | - (void)commonInit {
85 | // pan gesture
86 | self.panGestureRecognizer = [[UIPanGestureRecognizer alloc]initWithTarget:self action:@selector(handlePanGesture:)];
87 | [self addGestureRecognizer:_panGestureRecognizer];
88 | [self.panGestureRecognizer addObserver:self forKeyPath:@"state" options:NSKeyValueObservingOptionNew | NSKeyValueObservingOptionOld context:STHeaderViewPanGestureRecognizerStateContext];
89 | // animator
90 | self.animator = [[UIDynamicAnimator alloc]initWithReferenceView:self];
91 | self.animator.delegate = self;
92 | self.dynamicItem = [[STDynamicItem alloc]init];
93 | }
94 |
95 | - (void)handlePanGesture:(UIPanGestureRecognizer *)panGestureRecognizer {
96 |
97 | switch (panGestureRecognizer.state) {
98 | // remove animator
99 | case UIGestureRecognizerStateBegan:
100 | {
101 | [self endDecelerating];
102 | self.tracking = YES;
103 | }
104 | // change offset and add RubberBanding effect
105 | case UIGestureRecognizerStateChanged:
106 | {
107 | self.tracking = YES;
108 | self.dragging = YES;
109 | CGRect frame = self.frame;
110 | CGPoint translation = [panGestureRecognizer translationInView:self.superview];
111 | CGFloat newFrameOrginY = frame.origin.y + translation.y;
112 | CGPoint minFrameOrgin = [self minFrameOrgin];
113 | CGPoint maxFrameOrgin = [self maxFrameOrgin];
114 |
115 | CGFloat minFrameOrginY = minFrameOrgin.y;
116 | CGFloat maxFrameOrginY = maxFrameOrgin.y;
117 | CGFloat constrainedOrignY = fmax(minFrameOrginY, fmin(newFrameOrginY, maxFrameOrginY));
118 | CGFloat rubberBandedRate = rubberBandRate(newFrameOrginY - constrainedOrignY);
119 |
120 | frame.origin = CGPointMake(frame.origin.x, frame.origin.y + translation.y * rubberBandedRate);
121 | self.newFrame = frame;
122 |
123 | [panGestureRecognizer setTranslation:CGPointMake(translation.x, 0) inView:self.superview];
124 | }
125 | break;
126 | case UIGestureRecognizerStateEnded:
127 | {
128 | self.tracking = NO;
129 | self.dragging = NO;
130 | CGPoint velocity = [panGestureRecognizer velocityInView:self];
131 | // only support vertical
132 | velocity.x = 0;
133 |
134 | self.dynamicItem.center = self.frame.origin;
135 | self.decelerationBehavior = [[UIDynamicItemBehavior alloc] initWithItems:@[self.dynamicItem]];
136 | [_decelerationBehavior addLinearVelocity:velocity forItem:self.dynamicItem];
137 | _decelerationBehavior.resistance = 2;
138 |
139 | __weak typeof(self) weakSelf = self;
140 | _decelerationBehavior.action = ^{
141 | CGPoint center = weakSelf.dynamicItem.center;
142 | center.x = weakSelf.frame.origin.x;
143 | CGRect frame = weakSelf.frame;
144 | frame.origin = center;
145 | weakSelf.newFrame = frame;
146 | };
147 |
148 | [self.animator addBehavior:_decelerationBehavior];
149 | }
150 | break;
151 |
152 | default:
153 | {
154 | self.tracking = NO;
155 | self.dragging = NO;
156 | }
157 | break;
158 | }
159 |
160 | if (_delegate && [_delegate respondsToSelector:@selector(headerView:didPan:)]) {
161 | [_delegate headerView:self didPan:panGestureRecognizer];
162 | }
163 | }
164 |
165 | - (void)setNewFrame:(CGRect)frame {
166 | [self setFrame:frame];
167 |
168 | CGPoint minFrameOrgin = [self minFrameOrgin];
169 | CGPoint maxFrameOrgin = [self maxFrameOrgin];
170 |
171 | BOOL outsideFrameMinimum = frame.origin.y < minFrameOrgin.y;
172 | BOOL outsideFrameMaximum = frame.origin.y > maxFrameOrgin.y;
173 |
174 | if ((outsideFrameMinimum || outsideFrameMaximum) &&
175 | (_decelerationBehavior && !_springBehavior)) {
176 |
177 | CGPoint target = frame.origin;
178 | if (outsideFrameMinimum) {
179 | target.x = fmax(target.x, minFrameOrgin.x);
180 | target.y = fmax(target.y, minFrameOrgin.y);
181 | } else if (outsideFrameMaximum) {
182 | target.x = fmin(target.x, maxFrameOrgin.x);
183 | target.y = fmin(target.y, maxFrameOrgin.y);
184 | }
185 |
186 | self.springBehavior = [[UIAttachmentBehavior alloc] initWithItem:self.dynamicItem attachedToAnchor:target];
187 | // Has to be equal to zero, because otherwise the frame wouldn't exactly match the target's position.
188 | _springBehavior.length = 0;
189 | // These two values were chosen by trial and error.
190 | _springBehavior.damping = 1;
191 | _springBehavior.frequency = 2;
192 |
193 | [self.animator addBehavior:_springBehavior];
194 | }
195 |
196 | if (_delegate && [_delegate respondsToSelector:@selector(headerViewDidFrameChanged:)]) {
197 | [_delegate headerViewDidFrameChanged:self];
198 | }
199 | }
200 |
201 | - (CGPoint)minFrameOrgin {
202 | CGPoint orgin = CGPointMake(0, 0);
203 | if (_delegate && [_delegate respondsToSelector:@selector(minHeaderViewFrameOrgin)]) {
204 | orgin = [_delegate minHeaderViewFrameOrgin];
205 | }
206 | return orgin;
207 | }
208 |
209 | - (CGPoint)maxFrameOrgin {
210 | CGPoint orgin = CGPointMake(0, 0);
211 | if (_delegate && [_delegate respondsToSelector:@selector(maxHeaderViewFrameOrgin)]) {
212 | orgin = [_delegate maxHeaderViewFrameOrgin];
213 | }
214 | return orgin;
215 | }
216 |
217 | - (void)endDecelerating {
218 | [self.animator removeAllBehaviors];
219 | [self setDecelerationBehavior:nil];
220 | [self setSpringBehavior:nil];
221 | }
222 |
223 | - (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event {
224 | UIView * view = [super hitTest:point withEvent:event];
225 |
226 | // end header deceleraling when another began.
227 | [self endDecelerating];
228 |
229 | // tap inside of the header view
230 | if (CGRectContainsPoint(self.bounds, point)) {
231 | // return self to response this event,to avoid other view receiving this event when the header is decelerating.
232 | if (self.isDecelerating) {
233 | return self;
234 | }
235 | }
236 |
237 | return view;
238 | }
239 |
240 | #pragma mark - KVO
241 |
242 | - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context {
243 | if (context == STHeaderViewPanGestureRecognizerStateContext) {
244 | if (_delegate && [_delegate respondsToSelector:@selector(headerView:didPanGestureRecognizerStateChanged:)]) {
245 | [_delegate headerView:self didPanGestureRecognizerStateChanged:object];
246 | }
247 | }
248 | }
249 |
250 | #pragma mark - UIDynamicAnimatorDelegate
251 |
252 | - (void)dynamicAnimatorWillResume:(UIDynamicAnimator *)animator {
253 | self.decelerating = YES;
254 | }
255 |
256 | - (void)dynamicAnimatorDidPause:(UIDynamicAnimator *)animator {
257 | self.decelerating = NO;
258 | }
259 |
260 | @end
261 |
262 |
263 |
264 |
265 |
266 |
--------------------------------------------------------------------------------
/SwipeTableView/SwipeTableView/SwipeTableView.h:
--------------------------------------------------------------------------------
1 | //
2 | // SwipeTableView.h
3 | // SwipeTableView
4 | //
5 | // Created by Roy lee on 16/4/1.
6 | // Copyright © 2016年 Roy lee. All rights reserved.
7 | //
8 |
9 | #import
10 | #import "STHeaderView.h"
11 |
12 | @protocol SwipeTableViewDataSource;
13 | @protocol SwipeTableViewDelegate;
14 | @interface SwipeTableView : UIView
15 |
16 | @property (nonatomic, weak) iddelegate;
17 | @property (nonatomic, weak) iddataSource;
18 | @property (nonatomic, readonly, strong) UICollectionView * contentView;
19 |
20 | /*****************************************************************************************************/
21 | /**
22 | 如果项目想要支持常用的下拉刷新控件,如MJRefresh等。需要满足以下条件:
23 |
24 | ①.需要在项目PCH文件或者当前.h文件中设置如下的宏:#define ST_PULLTOREFRESH_HEADER_HEIGHT xx
25 | ②.定义的宏中`xx`要与您使用的第三方下拉刷新控件的refreshHeader高度相同:
26 | `MJRefresh` 为 `MJRefreshHeaderHeight`,`SVPullToRefresh` 为 `SVPullToRefreshViewHeight`
27 | */
28 | /*****************************************************************************************************/
29 | //#define ST_PULLTOREFRESH_HEADER_HEIGHT 60.0
30 |
31 | /**
32 | * 自定义显示在swipeView顶端的headerView,可以通过setter方法动态设置
33 | * 如果想要支持拖动swipeHeaderView,滚动当前页面的currentItemView,需要自定义的header继承自'STHeaderView',或者以'STHeaderView'的实例作为父视图
34 | */
35 | @property (nonatomic, strong) UIView * swipeHeaderView;
36 |
37 | /**
38 | * 自定义显示在swipeView顶端的headerBar,可以通过setter方法动态设置
39 | */
40 | @property (nonatomic, strong) UIView * swipeHeaderBar;
41 |
42 | /**
43 | * swipeView顶端headerView顶部的留白inset,这个属性可以设置顶部导航栏的inset,默认是 64
44 | */
45 | @property (nonatomic, assign) CGFloat swipeHeaderTopInset;
46 |
47 | /**
48 | * 当前itemView的index,在滑动swipeView过程中,index的变化以显示窗口的1/2宽为界限
49 | */
50 | @property (nonatomic, readonly) NSInteger currentItemIndex;
51 |
52 | /**
53 | * 当前itemView,在滑动swipeView过程中,currentItemView的变化以显示窗口的1/2宽为界限
54 | */
55 | @property (nonatomic, readonly, strong) UIScrollView * currentItemView;
56 |
57 | /**
58 | * swipeView是否开启水平bounce效果,默认为 YES
59 | */
60 | @property (nonatomic, assign) BOOL alwaysBounceHorizontal;
61 |
62 | /**
63 | * 在实际中,不同item的listView显示的数据多少不同。当数据多的item垂直滚动后,水平切换到数据少的item时,后一个item垂直滚动的范围便小于前一个item的垂直滚动范围。此时操作当前的item会产生一个回弹的动作。
64 | * 设置这个属性,可以调整前后两个item的滚动范围一致。默认为 NO
65 | */
66 | @property (nonatomic, assign) BOOL shouldAdjustContentSize;
67 |
68 | /**
69 | * swipeHeaderBar是否跟随滚动,默认为 NO。如果设置为YES,在没有swipeHeaderView的条件下,可以实现类似网易新闻首页效果
70 | */
71 | @property (nonatomic, assign) BOOL swipeHeaderBarScrollDisabled;
72 |
73 | @property (nonatomic, assign) BOOL scrollEnabled;
74 |
75 |
76 | - (void)reloadData;
77 | - (void)scrollToItemAtIndex:(NSInteger)index animated:(BOOL)animated;
78 |
79 | @end
80 |
81 |
82 |
83 | @protocol SwipeTableViewDataSource
84 |
85 | - (NSInteger)numberOfItemsInSwipeTableView:(SwipeTableView *)swipeView;
86 | - (UIScrollView *)swipeTableView:(SwipeTableView *)swipeView viewForItemAtIndex:(NSInteger)index reusingView:(UIScrollView *)view;
87 |
88 | @end
89 |
90 | @protocol SwipeTableViewDelegate
91 |
92 | @optional
93 | - (void)swipeTableViewDidScroll:(SwipeTableView *)swipeView;
94 | - (void)swipeTableViewCurrentItemIndexDidChange:(SwipeTableView *)swipeView;
95 | - (void)swipeTableViewWillBeginDragging:(SwipeTableView *)swipeView;
96 | - (void)swipeTableViewDidEndDragging:(SwipeTableView *)swipeView willDecelerate:(BOOL)decelerate;
97 | - (void)swipeTableViewWillBeginDecelerating:(SwipeTableView *)swipeView;
98 | - (void)swipeTableViewDidEndDecelerating:(SwipeTableView *)swipeView;
99 | - (void)swipeTableViewDidEndScrollingAnimation:(SwipeTableView *)swipeView;
100 | - (BOOL)swipeTableView:(SwipeTableView *)swipeView shouldSelectItemAtIndex:(NSInteger)index;
101 | - (void)swipeTableView:(SwipeTableView *)swipeView didSelectItemAtIndex:(NSInteger)index;
102 |
103 |
104 | /**
105 | * ①.在没有设置宏 #define ST_PULLTOREFRESH_HEADER_HEIGHT 的时候,想要通过自定义下拉刷新控件,并改写下拉刷新控件frame的方式支持下拉刷新。下面的两个方法必须实现。
106 | * ②.在定义了宏 #define ST_PULLTOREFRESH_HEADER_HEIGHT 的条件下,这两个方法可以灵活的调整每个item的下拉刷新有无,以及刷新控件的高度(RefreshHeader全部显露的高度)
107 | */
108 | - (BOOL)swipeTableView:(SwipeTableView *)swipeTableView shouldPullToRefreshAtIndex:(NSInteger)index; // default is YES if defined ST_PULLTOREFRESH_HEADER_HEIGHT,otherwise is NO.
109 | - (CGFloat)swipeTableView:(SwipeTableView *)swipeTableView heightForRefreshHeaderAtIndex:(NSInteger)index; // default is ST_PULLTOREFRESH_HEADER_HEIGHT if defined ST_PULLTOREFRESH_HEADER_HEIGHT,otherwise is CGFLOAT_MAX(not set pull to refesh).
110 |
111 | @end
112 |
113 |
114 | /** Weak refrence of SwipeTableView for UIScrollView */
115 | @interface UIScrollView (SwipeTableView)
116 | @property (nonatomic, readonly, weak) SwipeTableView * swipeTableView;
117 | @end
118 |
119 |
--------------------------------------------------------------------------------
/SwipeTableView/SwipeTableView/UIView+STFrame.h:
--------------------------------------------------------------------------------
1 | //
2 | // UIView+STFrame.h
3 | // SwipeTableView
4 | //
5 | // Created by Roy lee on 16/4/1.
6 | // Copyright © 2016年 Roy lee. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | @interface UIView (STFrame)
12 |
13 | @property (nonatomic, assign) CGFloat st_x;
14 | @property (nonatomic, assign) CGFloat st_y;
15 | @property (nonatomic, assign) CGFloat st_width;
16 | @property (nonatomic, assign) CGFloat st_height;
17 | @property (nonatomic, assign) CGFloat st_centerX;
18 | @property (nonatomic, assign) CGFloat st_centerY;
19 | @property (nonatomic, assign) CGSize st_size;
20 | @property (nonatomic, assign) CGFloat st_top;
21 | @property (nonatomic, assign) CGFloat st_bottom;
22 | @property (nonatomic, assign) CGFloat st_left;
23 | @property (nonatomic, assign) CGFloat st_right;
24 |
25 | @end
26 |
--------------------------------------------------------------------------------
/SwipeTableView/SwipeTableView/UIView+STFrame.m:
--------------------------------------------------------------------------------
1 | //
2 | // UIView+STFrame.m
3 | // SwipeTableView
4 | //
5 | // Created by Roy lee on 16/4/1.
6 | // Copyright © 2016年 Roy lee. All rights reserved.
7 | //
8 |
9 | #import "UIView+STFrame.h"
10 |
11 | @implementation UIView (Frame)
12 |
13 | -(CGFloat)st_x {
14 | return self.frame.origin.x;
15 | }
16 |
17 | -(void)setSt_x:(CGFloat)x {
18 | CGRect rect = self.frame;
19 | rect.origin.x = x;
20 | self.frame = rect;
21 | }
22 |
23 | -(CGFloat)st_y {
24 | return self.frame.origin.y;
25 | }
26 |
27 | -(void)setSt_y:(CGFloat)y {
28 | CGRect rect = self.frame;
29 | rect.origin.y = y;
30 | self.frame = rect;
31 | }
32 |
33 | -(CGFloat)st_width {
34 | return self.frame.size.width;
35 | }
36 |
37 | -(void)setSt_width:(CGFloat)width {
38 | CGRect rect = self.frame;
39 | rect.size.width = width;
40 | self.frame = rect;
41 | }
42 |
43 | -(CGFloat)st_height {
44 | return self.frame.size.height;
45 | }
46 |
47 | -(void)setSt_height:(CGFloat)height {
48 | CGRect rect = self.frame;
49 | rect.size.height = height;
50 | self.frame = rect;
51 | }
52 |
53 | -(CGFloat)st_centerX {
54 | return self.center.x;
55 | }
56 |
57 | -(void)setSt_centerX:(CGFloat)centerX {
58 | CGPoint center = self.center;
59 | center.x = centerX;
60 | self.center = center;
61 | }
62 |
63 | -(CGFloat)st_centerY {
64 | return self.center.y;
65 | }
66 |
67 | -(void)setSt_centerY:(CGFloat)centerY {
68 | CGPoint center = self.center;
69 | center.y = centerY;
70 | self.center = center;
71 | }
72 |
73 | - (CGSize)st_size {
74 | return self.frame.size;
75 | }
76 |
77 | - (void)setSt_size:(CGSize)size {
78 | CGRect frame = self.frame;
79 | frame.size = size;
80 | self.frame = frame;
81 | }
82 |
83 | - (CGFloat)st_top {
84 | return self.frame.origin.y;
85 | }
86 |
87 | - (void)setSt_top:(CGFloat)t {
88 | self.frame = CGRectMake(self.st_left, t, self.st_width, self.st_height);
89 | }
90 |
91 | - (CGFloat)st_bottom {
92 | return self.frame.origin.y + self.frame.size.height;
93 | }
94 |
95 | - (void)setSt_bottom:(CGFloat)b {
96 | self.frame = CGRectMake(self.st_left, b - self.st_height, self.st_width, self.st_height);
97 | }
98 |
99 | - (CGFloat)st_left {
100 | return self.frame.origin.x;
101 | }
102 |
103 | - (void)setSt_left:(CGFloat)l {
104 | self.frame = CGRectMake(l, self.st_top, self.st_width, self.st_height);
105 | }
106 |
107 | - (CGFloat)st_right {
108 | return self.frame.origin.x + self.frame.size.width;
109 | }
110 |
111 | - (void)setSt_right:(CGFloat)r {
112 | self.frame = CGRectMake(r - self.st_width, self.st_top, self.st_width, self.st_height);
113 | }
114 |
115 |
116 |
117 | @end
118 |
--------------------------------------------------------------------------------
/SwipeTableView/SwipeTableViewDemo/STController/STImageController.h:
--------------------------------------------------------------------------------
1 | //
2 | // STImageController.h
3 | // SwipeTableView
4 | //
5 | // Created by Roy lee on 16/6/24.
6 | // Copyright © 2016年 Roy lee. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | @interface STImageController : UIViewController
12 |
13 | @property (nonatomic, strong) UIImageView *imageView;
14 |
15 | @end
16 |
--------------------------------------------------------------------------------
/SwipeTableView/SwipeTableViewDemo/STController/STImageController.m:
--------------------------------------------------------------------------------
1 | //
2 | // STImageController.m
3 | // SwipeTableView
4 | //
5 | // Created by Roy lee on 16/6/24.
6 | // Copyright © 2016年 Roy lee. All rights reserved.
7 | //
8 |
9 | #import "STImageController.h"
10 | #import "UIView+STFrame.h"
11 |
12 | @interface STImageController ()
13 |
14 | @end
15 |
16 | @implementation STImageController
17 |
18 | - (void)viewDidLoad {
19 | [super viewDidLoad];
20 |
21 | self.view.backgroundColor = [UIColor blackColor];
22 | self.imageView = [[UIImageView alloc]init];
23 | _imageView.st_width = [UIScreen mainScreen].bounds.size.width;
24 | _imageView.userInteractionEnabled = YES;
25 | [self.view addSubview:_imageView];
26 |
27 | UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapImageView:)];
28 | [self.view addGestureRecognizer:tap];
29 | }
30 |
31 | - (void)tapImageView:(UITapGestureRecognizer *)tap {
32 | [self dismissViewControllerAnimated:YES completion:nil];
33 | }
34 |
35 | - (void)didReceiveMemoryWarning {
36 | [super didReceiveMemoryWarning];
37 | // Dispose of any resources that can be recreated.
38 | }
39 |
40 | /*
41 | #pragma mark - Navigation
42 |
43 | // In a storyboard-based application, you will often want to do a little preparation before navigation
44 | - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
45 | // Get the new view controller using [segue destinationViewController].
46 | // Pass the selected object to the new view controller.
47 | }
48 | */
49 |
50 | @end
51 |
--------------------------------------------------------------------------------
/SwipeTableView/SwipeTableViewDemo/STController/STListController.h:
--------------------------------------------------------------------------------
1 | //
2 | // STListController.h
3 | // SwipeTableView
4 | //
5 | // Created by Roy lee on 16/4/2.
6 | // Copyright © 2016年 Roy lee. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | @interface STListController : UITableViewController
12 |
13 | @end
14 |
--------------------------------------------------------------------------------
/SwipeTableView/SwipeTableViewDemo/STController/STListController.m:
--------------------------------------------------------------------------------
1 | //
2 | // STListController.m
3 | // SwipeTableView
4 | //
5 | // Created by Roy lee on 16/4/2.
6 | // Copyright © 2016年 Roy lee. All rights reserved.
7 | //
8 |
9 | #import "STListController.h"
10 | #import "STViewController.h"
11 |
12 | @interface STListController ()
13 |
14 | @property (nonatomic, strong) NSArray * dataSource;
15 |
16 | @end
17 |
18 | @implementation STListController
19 |
20 | - (void)viewDidLoad {
21 | [super viewDidLoad];
22 |
23 | self.dataSource = @[@{
24 | @"title":@"SingleOneKindView",
25 | @"type":@(STControllerTypeNormal),
26 | },
27 | @{
28 | @"title":@"HybridItemViews",
29 | @"type":@(STControllerTypeHybrid),
30 | },
31 | @{
32 | @"title":@"DisabledBarScroll",
33 | @"type":@(STControllerTypeDisableBarScroll),
34 | },
35 | @{
36 | @"title":@"HiddenNavigationBar",
37 | @"type":@(STControllerTypeHiddenNavBar),
38 | }];
39 | }
40 |
41 | #pragma mark - UITableView M
42 | - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
43 | return _dataSource.count;
44 | }
45 |
46 | - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
47 | UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"list_cell" forIndexPath:indexPath];
48 | cell.textLabel.text = _dataSource[indexPath.row][@"title"];
49 | return cell;
50 | }
51 |
52 | // In a storyboard-based application, you will often want to do a little preparation before navigation
53 | - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
54 | // Get the new view controller using [segue destinationViewController].
55 | // Pass the selected object to the new view controller.
56 | STViewController * demoVC = [segue destinationViewController];
57 | UITableViewCell * cell = sender;
58 | NSIndexPath * indexPath = [self.tableView indexPathForCell:cell];
59 | demoVC.type = (STControllerType)[_dataSource[indexPath.row][@"type"] integerValue];
60 | demoVC.title = _dataSource[indexPath.row][@"title"];
61 | [super prepareForSegue:segue sender:sender];
62 | [self.tableView deselectRowAtIndexPath:indexPath animated:YES];
63 | }
64 |
65 | - (void)didReceiveMemoryWarning {
66 | [super didReceiveMemoryWarning];
67 | // Dispose of any resources that can be recreated.
68 | }
69 |
70 | @end
71 |
--------------------------------------------------------------------------------
/SwipeTableView/SwipeTableViewDemo/STController/STViewController.h:
--------------------------------------------------------------------------------
1 | //
2 | // STViewController.h
3 | // SwipeTableView
4 | //
5 | // Created by Roy lee on 16/4/1.
6 | // Copyright © 2016年 Roy lee. All rights reserved.
7 | //
8 |
9 | #import
10 | #define RGBColorAlpha(r,g,b,f) [UIColor colorWithRed:r/255.0 green:g/255.0 blue:b/255.0 alpha:f]
11 | #define RGBColor(r,g,b) RGBColorAlpha(r,g,b,1)
12 |
13 | typedef NS_ENUM(NSInteger,STControllerType) {
14 | STControllerTypeNormal,
15 | STControllerTypeHybrid,
16 | STControllerTypeDisableBarScroll,
17 | STControllerTypeHiddenNavBar,
18 | };
19 |
20 | @interface STViewController : UIViewController
21 |
22 | @property (nonatomic, assign) STControllerType type;
23 | @property (nonatomic, strong) UIImageView * headerImageView;
24 |
25 | @end
26 |
27 |
28 |
--------------------------------------------------------------------------------
/SwipeTableView/SwipeTableViewDemo/STController/STViewController.m:
--------------------------------------------------------------------------------
1 | //
2 | // STViewController.m
3 | // SwipeTableView
4 | //
5 | // Created by Roy lee on 16/4/1.
6 | // Copyright © 2016年 Roy lee. All rights reserved.
7 | //
8 |
9 | #import "STViewController.h"
10 | #import "SwipeTableView.h"
11 | #import "CustomTableView.h"
12 | #import "CustomCollectionView.h"
13 | #import "CustomSegmentControl.h"
14 | #import "UIView+STFrame.h"
15 | #import "STImageController.h"
16 | #import "STTransitions.h"
17 | #import "STRefresh.h"
18 | #import
19 |
20 |
21 | @interface STViewController ()
22 |
23 | @property (nonatomic, strong) SwipeTableView * swipeTableView;
24 | @property (nonatomic, strong) STHeaderView * tableViewHeader;
25 | @property (nonatomic, strong) CustomSegmentControl * segmentBar;
26 | @property (nonatomic, strong) CustomTableView * tableView;
27 | @property (nonatomic, strong) CustomCollectionView * collectionView;
28 | @property (nonatomic, strong) NSMutableDictionary * dataDic;
29 |
30 | @end
31 |
32 | @implementation STViewController
33 |
34 | - (void)viewDidLoad {
35 | [super viewDidLoad];
36 |
37 | BOOL disableBarScroll = _type == STControllerTypeDisableBarScroll;
38 | BOOL hiddenNavigationBar = _type == STControllerTypeHiddenNavBar;
39 |
40 | // init swipetableview
41 | self.swipeTableView = [[SwipeTableView alloc]initWithFrame:self.view.bounds];
42 | _swipeTableView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
43 | _swipeTableView.delegate = self;
44 | _swipeTableView.dataSource = self;
45 | _swipeTableView.shouldAdjustContentSize = YES;
46 | _swipeTableView.swipeHeaderView = disableBarScroll?nil:self.tableViewHeader;
47 | _swipeTableView.swipeHeaderBar = self.segmentBar;
48 | _swipeTableView.swipeHeaderBarScrollDisabled = disableBarScroll;
49 | if (hiddenNavigationBar) {
50 | _swipeTableView.swipeHeaderTopInset = 0;
51 | }
52 | [self.view addSubview:_swipeTableView];
53 |
54 | // nav bar
55 | UIBarButtonItem * rightBarItem = [[UIBarButtonItem alloc]initWithTitle:@"- Header" style:UIBarButtonItemStylePlain target:self action:@selector(setSwipeTableHeader:)];
56 | UIBarButtonItem * leftBarItem = [[UIBarButtonItem alloc]initWithTitle:@"- Bar" style:UIBarButtonItemStylePlain target:self action:@selector(setSwipeTableBar:)];
57 | self.navigationItem.leftBarButtonItem = disableBarScroll?nil:leftBarItem;
58 | self.navigationItem.rightBarButtonItem = disableBarScroll?nil:rightBarItem;
59 |
60 | // back bt
61 | UIButton * back = [UIButton buttonWithType:UIButtonTypeCustom];
62 | back.frame = CGRectMake(10, 0, 40, 40);
63 | back.st_top = hiddenNavigationBar?25:74;
64 | back.backgroundColor = RGBColorAlpha(10, 202, 0, 0.95);
65 | back.layer.cornerRadius = back.st_height/2;
66 | back.layer.masksToBounds = YES;
67 | back.titleLabel.font = [UIFont boldSystemFontOfSize:14];
68 | back.hidden = disableBarScroll;
69 | [back setTitle:@"Back" forState:UIControlStateNormal];
70 | [back setTitleColor:RGBColor(255, 255, 215) forState:UIControlStateNormal];
71 | [back addTarget:self action:@selector(back) forControlEvents:UIControlEventTouchUpInside];
72 | [self.view addSubview:back];
73 |
74 | [self.navigationController.navigationBar setTintColor:RGBColor(234, 39, 0)];
75 |
76 | // edge gesture
77 | [_swipeTableView.contentView.panGestureRecognizer requireGestureRecognizerToFail:self.screenEdgePanGestureRecognizer];
78 |
79 | // init data
80 | _dataDic = [@{} mutableCopy];
81 |
82 | // 根据滚动后的下标请求数据
83 | // [self getDataAtIndex:0];
84 |
85 | // 一次性请求所有item的数据
86 | [self getAllData];
87 | }
88 |
89 | - (UIScreenEdgePanGestureRecognizer *)screenEdgePanGestureRecognizer {
90 | UIScreenEdgePanGestureRecognizer *screenEdgePanGestureRecognizer = nil;
91 | if (self.navigationController.view.gestureRecognizers.count > 0) {
92 | for (UIGestureRecognizer *recognizer in self.navigationController.view.gestureRecognizers) {
93 | if ([recognizer isKindOfClass:[UIScreenEdgePanGestureRecognizer class]]) {
94 | screenEdgePanGestureRecognizer = (UIScreenEdgePanGestureRecognizer *)recognizer;
95 | break;
96 | }
97 | }
98 | }
99 | return screenEdgePanGestureRecognizer;
100 | }
101 |
102 | #pragma mark - Header & Bar
103 |
104 | - (UIView *)tableViewHeader {
105 | if (nil == _tableViewHeader) {
106 | UIImage * headerImage = [UIImage imageNamed:@"onepiece_kiudai"];
107 | // swipe header
108 | self.tableViewHeader = [[STHeaderView alloc]init];
109 | _tableViewHeader.frame = CGRectMake(0, 0, kScreenWidth, kScreenWidth * (headerImage.size.height/headerImage.size.width));
110 | _tableViewHeader.backgroundColor = [UIColor whiteColor];
111 | _tableViewHeader.layer.masksToBounds = YES;
112 |
113 | // image view
114 | self.headerImageView = [[UIImageView alloc]initWithImage:headerImage];
115 | _headerImageView.contentMode = UIViewContentModeScaleAspectFill;
116 | _headerImageView.userInteractionEnabled = YES;
117 | _headerImageView.frame = _tableViewHeader.bounds;
118 | _headerImageView.autoresizingMask = UIViewAutoresizingFlexibleHeight;
119 |
120 | // title label
121 | UILabel * title = [[UILabel alloc]init];
122 | title.textColor = RGBColor(255, 255, 255);
123 | title.font = [UIFont boldSystemFontOfSize:17];
124 | title.text = @"Tap To Full Screen";
125 | title.textAlignment = NSTextAlignmentCenter;
126 | title.st_size = CGSizeMake(200, 30);
127 | title.st_centerX = _headerImageView.st_centerX;
128 | title.st_bottom = _headerImageView.st_bottom - 20;
129 |
130 | // tap gesture
131 | UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapHeader:)];
132 |
133 | [_tableViewHeader addSubview:_headerImageView];
134 | [_tableViewHeader addSubview:title];
135 | [_headerImageView addGestureRecognizer:tap];
136 | [self shimmerHeaderTitle:title];
137 | }
138 | return _tableViewHeader;
139 | }
140 |
141 | - (CustomSegmentControl * )segmentBar {
142 | if (nil == _segmentBar) {
143 | self.segmentBar = [[CustomSegmentControl alloc]initWithItems:@[@"Item0",@"Item1",@"Item2",@"Item3"]];
144 | _segmentBar.st_size = CGSizeMake(kScreenWidth, 40);
145 | _segmentBar.font = [UIFont systemFontOfSize:15];
146 | _segmentBar.textColor = RGBColor(100, 100, 100);
147 | _segmentBar.selectedTextColor = RGBColor(0, 0, 0);
148 | _segmentBar.backgroundColor = RGBColor(249, 251, 198);
149 | _segmentBar.selectionIndicatorColor = RGBColor(249, 104, 92);
150 | _segmentBar.selectedSegmentIndex = _swipeTableView.currentItemIndex;
151 | [_segmentBar addTarget:self action:@selector(changeSwipeViewIndex:) forControlEvents:UIControlEventValueChanged];
152 | }
153 | return _segmentBar;
154 | }
155 |
156 | #pragma mark -
157 |
158 | - (void)back {
159 | [self.navigationController popViewControllerAnimated:YES];
160 | }
161 |
162 | - (void)tapHeader:(UITapGestureRecognizer *)tap {
163 | STImageController * imageVC = [[STImageController alloc]init];
164 | imageVC.transitioningDelegate = self;
165 | [self presentViewController:imageVC animated:YES completion:nil];
166 | }
167 |
168 | // tap to change header's frame
169 | - (void)_tapHeader:(UITapGestureRecognizer *)tap {
170 |
171 | CGFloat changeHeight = 50; // or -50, it will be parallax.
172 | UIScrollView * currentItem = _swipeTableView.currentItemView;
173 | #if !defined(ST_PULLTOREFRESH_HEADER_HEIGHT)
174 | CGPoint contentOffset = currentItem.contentOffset;
175 | UIEdgeInsets inset = currentItem.contentInset;
176 | inset.top += changeHeight;
177 | contentOffset.y -= changeHeight; // if you want the header change height from up, not do this.
178 |
179 | NSMutableDictionary * contentOffsetQuene = [self.swipeTableView valueForKey:@"contentOffsetQuene"];
180 | [contentOffsetQuene removeAllObjects];
181 |
182 | [UIView animateWithDuration:.35f delay:0 options:UIViewAnimationOptionCurveEaseInOut animations:^{
183 | _tableViewHeader.st_height += changeHeight;
184 | currentItem.contentInset = inset;
185 | currentItem.contentOffset = contentOffset;
186 | } completion:^(BOOL finished) {
187 | [self.swipeTableView setValue:@(self.tableViewHeader.st_height) forKey:@"headerInset"];
188 | }];
189 | #else
190 | UIView * tableHeaderView = ((UITableView *)currentItem).tableHeaderView;
191 | tableHeaderView.st_height += changeHeight;
192 |
193 | [UIView animateWithDuration:.35f delay:0 options:UIViewAnimationOptionCurveEaseInOut animations:^{
194 | _tableViewHeader.st_height += changeHeight;
195 | [currentItem setValue:tableHeaderView forKey:@"tableHeaderView"];
196 | } completion:^(BOOL finished) {
197 | [self.swipeTableView setValue:@(self.tableViewHeader.st_height) forKey:@"headerInset"];
198 | }];
199 | #endif
200 |
201 | }
202 |
203 | - (void)shimmerHeaderTitle:(UILabel *)title {
204 | __weak typeof(self) weakSelf = self;
205 | [UIView animateWithDuration:0.75f delay:0 options:UIViewAnimationOptionCurveEaseInOut animations:^{
206 | title.transform = CGAffineTransformMakeScale(0.98, 0.98);
207 | title.alpha = 0.3;
208 | } completion:^(BOOL finished) {
209 | [UIView animateWithDuration:0.75f delay:0 options:UIViewAnimationOptionCurveEaseInOut animations:^{
210 | title.alpha = 1.0;
211 | title.transform = CGAffineTransformIdentity;
212 | } completion:^(BOOL finished) {
213 | [weakSelf shimmerHeaderTitle:title];
214 | }];
215 | }];
216 | }
217 |
218 | - (void)setSwipeTableHeader:(UIBarButtonItem *)barItem {
219 | if (!_swipeTableView.swipeHeaderView) {
220 | _swipeTableView.swipeHeaderView = self.tableViewHeader;
221 | [_swipeTableView reloadData];
222 |
223 | UIBarButtonItem * rightBarItem = [[UIBarButtonItem alloc]initWithTitle:@"- Header" style:UIBarButtonItemStylePlain target:self action:@selector(setSwipeTableHeader:)];
224 | self.navigationItem.rightBarButtonItem = rightBarItem;
225 | }else {
226 | _swipeTableView.swipeHeaderView = nil;
227 |
228 | UIBarButtonItem * rightBarItem = [[UIBarButtonItem alloc]initWithTitle:@"+ Header" style:UIBarButtonItemStylePlain target:self action:@selector(setSwipeTableHeader:)];
229 | self.navigationItem.rightBarButtonItem = rightBarItem;
230 | }
231 | }
232 |
233 | - (void)setSwipeTableBar:(UIBarButtonItem *)barItem {
234 | if (!_swipeTableView.swipeHeaderBar) {
235 | _swipeTableView.swipeHeaderBar = self.segmentBar;
236 | _swipeTableView.scrollEnabled = YES;
237 |
238 | UIBarButtonItem * leftBarItem = [[UIBarButtonItem alloc]initWithTitle:@"- Bar" style:UIBarButtonItemStylePlain target:self action:@selector(setSwipeTableBar:)];
239 | self.navigationItem.leftBarButtonItem = leftBarItem;
240 | }else {
241 | _swipeTableView.swipeHeaderBar = nil;
242 | _swipeTableView.scrollEnabled = NO;
243 |
244 | UIBarButtonItem * leftBarItem = [[UIBarButtonItem alloc]initWithTitle:@"+ Bar" style:UIBarButtonItemStylePlain target:self action:@selector(setSwipeTableBar:)];
245 | self.navigationItem.leftBarButtonItem = leftBarItem;
246 | }
247 | }
248 |
249 | - (CustomTableView *)tableView {
250 | if (nil == _tableView) {
251 | _tableView = [[CustomTableView alloc]initWithFrame:_swipeTableView.bounds style:UITableViewStylePlain];
252 | _tableView.backgroundColor = RGBColor(255, 255, 225);
253 | }
254 | return _tableView;
255 | }
256 |
257 | - (CustomCollectionView *)collectionView {
258 | if (nil == _collectionView) {
259 | _collectionView = [[CustomCollectionView alloc]initWithFrame:_swipeTableView.bounds];
260 | _collectionView.backgroundColor = RGBColor(255, 255, 225);
261 | }
262 | return _collectionView;
263 | }
264 |
265 | - (void)changeSwipeViewIndex:(UISegmentedControl *)seg {
266 | [_swipeTableView scrollToItemAtIndex:seg.selectedSegmentIndex animated:NO];
267 | // request data at current index
268 | [self getDataAtIndex:seg.selectedSegmentIndex];
269 | }
270 |
271 | #pragma mark - Data Reuqest
272 |
273 | // 请求数据(根据视图滚动到相应的index后再请求数据)
274 | - (void)getDataAtIndex:(NSInteger)index {
275 | if (nil != _dataDic[@(index)]) {
276 | return;
277 | }
278 | NSInteger numberOfRows = 0;
279 | switch (index) {
280 | case 0:
281 | numberOfRows = _type == STControllerTypeNormal?8:10;
282 | break;
283 | case 1:
284 | numberOfRows = _type == STControllerTypeNormal?10:8;
285 | break;
286 | case 2:
287 | numberOfRows = _type == STControllerTypeNormal?5:6;
288 | break;
289 | case 3:
290 | numberOfRows = _type == STControllerTypeNormal?12:12;
291 | break;
292 | default:
293 | break;
294 | }
295 | // 请求数据后刷新相应的item
296 | ((void (*)(void *, SEL, NSNumber *, NSInteger))objc_msgSend)((__bridge void *)(self.swipeTableView.currentItemView),@selector(refreshWithData:atIndex:), @(numberOfRows),index);
297 | // 保存数据
298 | [_dataDic setObject:@(numberOfRows) forKey:@(index)];
299 | }
300 |
301 | // 请求数据(一次性获取所有item的数据)
302 | - (void)getAllData {
303 | if (_type == STControllerTypeNormal) {
304 | [_dataDic setObject:@(8) forKey:@(0)];
305 | [_dataDic setObject:@(10) forKey:@(1)];
306 | [_dataDic setObject:@(5) forKey:@(2)];
307 | [_dataDic setObject:@(12) forKey:@(3)];
308 | }else {
309 | [_dataDic setObject:@(10) forKey:@(0)];
310 | [_dataDic setObject:@(12) forKey:@(1)];
311 | [_dataDic setObject:@(8) forKey:@(2)];
312 | [_dataDic setObject:@(14) forKey:@(3)];
313 | }
314 | }
315 |
316 |
317 | #pragma mark - SwipeTableView M
318 |
319 | - (NSInteger)numberOfItemsInSwipeTableView:(SwipeTableView *)swipeView {
320 | return 4;
321 | }
322 |
323 | - (UIScrollView *)swipeTableView:(SwipeTableView *)swipeView viewForItemAtIndex:(NSInteger)index reusingView:(UIScrollView *)view {
324 | switch (_type) {
325 | case STControllerTypeNormal:
326 | {
327 |
328 | CustomTableView * tableView = (CustomTableView *)view;
329 | // 重用
330 | if (nil == tableView) {
331 | tableView = [[CustomTableView alloc]initWithFrame:swipeView.bounds style:UITableViewStylePlain];
332 | tableView.backgroundColor = RGBColor(255, 255, 225);
333 | }
334 |
335 | // 获取当前index下item的数据,进行数据刷新
336 | id data = _dataDic[@(index)];
337 | [tableView refreshWithData:data atIndex:index];
338 |
339 | view = tableView;
340 | }
341 | break;
342 | case STControllerTypeHybrid:
343 | case STControllerTypeDisableBarScroll:
344 | case STControllerTypeHiddenNavBar:
345 | {
346 |
347 | // 混合的itemview只有同类型的item采用重用
348 | if (index == 0 || index == 2) {
349 |
350 | // 懒加载保证同样类型的item只创建一次,以达到重用
351 | CustomTableView * tableView = self.tableView;
352 |
353 | // 获取当前index下item的数据,进行数据刷新
354 | id data = _dataDic[@(index)];
355 | [tableView refreshWithData:data atIndex:index];
356 |
357 | view = tableView;
358 | }else {
359 |
360 | CustomCollectionView * collectionView = self.collectionView;
361 |
362 | // 获取当前index下item的数据,进行数据刷新
363 | id data = _dataDic[@(index)];
364 | [collectionView refreshWithData:data atIndex:index];
365 |
366 | view = self.collectionView;
367 | }
368 |
369 | }
370 | break;
371 | default:
372 | break;
373 | }
374 |
375 | // 在没有设定下拉刷新宏的条件下,自定义的下拉刷新需要做 refreshheader 的 frame 处理
376 | [self configRefreshHeaderForItem:view];
377 |
378 | return view;
379 | }
380 |
381 | // swipetableView index变化,改变seg的index
382 | - (void)swipeTableViewCurrentItemIndexDidChange:(SwipeTableView *)swipeView {
383 | _segmentBar.selectedSegmentIndex = swipeView.currentItemIndex;
384 | }
385 |
386 | // 滚动结束请求数据
387 | - (void)swipeTableViewDidEndDecelerating:(SwipeTableView *)swipeView {
388 | [self getDataAtIndex:swipeView.currentItemIndex];
389 | }
390 |
391 | /**
392 | * 以下两个代理,在未定义宏 #define ST_PULLTOREFRESH_HEADER_HEIGHT,并自定义下拉刷新的时候,必须实现
393 | * 如果设置了下拉刷新的宏,以下代理可根据需要实现即可
394 | */
395 | - (BOOL)swipeTableView:(SwipeTableView *)swipeTableView shouldPullToRefreshAtIndex:(NSInteger)index {
396 | return YES;
397 | }
398 |
399 | - (CGFloat)swipeTableView:(SwipeTableView *)swipeTableView heightForRefreshHeaderAtIndex:(NSInteger)index {
400 | return kSTRefreshHeaderHeight;
401 | }
402 |
403 | /**
404 | * 采用自定义修改下拉刷新,此时不会定义宏 #define ST_PULLTOREFRESH_HEADER_HEIGHT
405 | * 对于一些下拉刷新控件,可能会在`layouSubViews`中设置RefreshHeader的frame。所以,需要在itemView有效的方法中改变RefreshHeader的frame,如 `scrollViewDidScroll:`
406 | */
407 | - (void)configRefreshHeaderForItem:(UIScrollView *)itemView {
408 | if (_type == STControllerTypeDisableBarScroll) {
409 | itemView.header = nil;
410 | return;
411 | }
412 | #if !defined(ST_PULLTOREFRESH_HEADER_HEIGHT)
413 | STRefreshHeader * header = itemView.header;
414 | header.st_y = - (header.st_height + (_segmentBar.st_height + _headerImageView.st_height));
415 | #endif
416 | }
417 |
418 |
419 |
420 | #pragma mark - UIViewControllerTransitioningDelegate
421 |
422 | - (id)animationControllerForPresentedController:(UIViewController *)presented
423 | presentingController:(UIViewController *)presenting sourceController:(UIViewController *)source {
424 |
425 | return [[STTransitions alloc]initWithTransitionDuration:0.55f fromView:self.headerImageView isPresenting:YES];
426 | }
427 |
428 | - (id )animationControllerForDismissedController:(UIViewController *)dismissed {
429 | return [[STTransitions alloc]initWithTransitionDuration:0.5f fromView:self.headerImageView isPresenting:NO];
430 | }
431 |
432 | - (void)viewWillAppear:(BOOL)animated {
433 | [super viewWillAppear:animated];
434 | [self.navigationController setNavigationBarHidden:_type == STControllerTypeHiddenNavBar animated:animated];
435 | }
436 |
437 | - (void)viewWillDisappear:(BOOL)animated {
438 | [super viewWillDisappear:animated];
439 | [self.navigationController setNavigationBarHidden:NO animated:animated];
440 | }
441 |
442 | - (void)viewDidAppear:(BOOL)animated {
443 | [super viewDidAppear:animated];
444 | __weak typeof(self) weakSelf = self;
445 | self.navigationController.interactivePopGestureRecognizer.delegate = weakSelf;
446 | }
447 |
448 | - (void)viewDidDisappear:(BOOL)animated {
449 | [super viewDidDisappear:animated];
450 | self.navigationController.interactivePopGestureRecognizer.delegate = nil;
451 | }
452 |
453 | - (void)didReceiveMemoryWarning {
454 | [super didReceiveMemoryWarning];
455 | // Dispose of any resources that can be recreated.
456 | }
457 |
458 | @end
459 |
--------------------------------------------------------------------------------
/SwipeTableView/SwipeTableViewDemo/STRefresh/STRefresh.h:
--------------------------------------------------------------------------------
1 | //
2 | // STRefresh.h
3 | // SwipeTableView
4 | //
5 | // Created by Roy lee on 16/7/10.
6 | // Copyright © 2016年 Roy lee. All rights reserved.
7 | //
8 |
9 | #ifndef STRefresh_h
10 | #define STRefresh_h
11 |
12 |
13 | #import "STRefreshHeader.h"
14 | #import "UIScrollView+STRefresh.h"
15 |
16 | #endif /* STRefresh_h */
17 |
--------------------------------------------------------------------------------
/SwipeTableView/SwipeTableViewDemo/STRefresh/STRefreshHeader.h:
--------------------------------------------------------------------------------
1 | //
2 | // STRefreshHeader.h
3 | // SwipeTableView
4 | //
5 | // Created by Roy lee on 16/7/10.
6 | // Copyright © 2016年 Roy lee. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | #define kSTRefreshHeaderHeight 60
12 | #define kSTRefreshImageWidth 40
13 |
14 | @interface STRefreshHeader : UIView
15 |
16 | + (instancetype)headerWithRefreshingBlock:(void(^)(STRefreshHeader * header))refreshingBlock;
17 | + (instancetype)headerWithRefreshingTarget:(id)target refreshingAction:(SEL)action;
18 |
19 | - (void)beganRefreshing;
20 | - (void)endRefreshing;
21 |
22 | @end
23 |
--------------------------------------------------------------------------------
/SwipeTableView/SwipeTableViewDemo/STRefresh/STRefreshHeader.m:
--------------------------------------------------------------------------------
1 | //
2 | // STRefreshHeader.m
3 | // SwipeTableView
4 | //
5 | // Created by Roy lee on 16/7/10.
6 | // Copyright © 2016年 Roy lee. All rights reserved.
7 | //
8 |
9 | #import "STRefreshHeader.h"
10 | #import "UIView+STFrame.h"
11 | #import
12 |
13 | #define RGBColor(r,g,b) [UIColor colorWithRed:r/255.0 green:g/255.0 blue:b/255.0 alpha:1]
14 | #define kSTRefreshCircleLineWidth 2.5
15 | #define kSTRefreshRoundTime 1.5
16 |
17 | typedef NS_ENUM(NSInteger,STRefreshState) {
18 | STRefreshStateNormal,
19 | STRefreshStatePulling,
20 | STRefreshStateRefeshing,
21 | STRefreshStateWillRefesh
22 | };
23 |
24 |
25 | @interface STRefreshHeader ()
26 |
27 | @property (nonatomic, weak) UIScrollView * scrollView;
28 | @property (nonatomic, strong) CAShapeLayer * circleLayer;
29 | @property (nonatomic, strong) UIView * contentView;
30 | @property (nonatomic, strong) UIImageView * headerImageV;
31 | @property (nonatomic, strong) NSArray * colorArray;
32 | @property (nonatomic, assign) CGFloat orginContentInsetTop;
33 | @property (nonatomic, assign) STRefreshState state;
34 | @property (nonatomic, assign) BOOL isAnimating;
35 | @property (nonatomic, copy) void(^refreshingBlock)(STRefreshHeader *);
36 | @property (weak, nonatomic) id refreshingTarget;
37 | @property (assign, nonatomic) SEL refreshingAction;
38 |
39 | @end
40 |
41 |
42 | static void * STRefreshContentOffsetContext = &STRefreshContentOffsetContext;
43 | static void * STRefreshcontentInsetContext = &STRefreshcontentInsetContext;
44 |
45 | @implementation STRefreshHeader
46 |
47 | + (instancetype)headerWithRefreshingBlock:(void(^)(STRefreshHeader * header))refreshingBlock {
48 | STRefreshHeader * header = [[STRefreshHeader alloc]init];
49 | header.refreshingBlock = refreshingBlock;
50 | return header;
51 | }
52 |
53 | + (instancetype)headerWithRefreshingTarget:(id)target refreshingAction:(SEL)action {
54 | STRefreshHeader * header = [[STRefreshHeader alloc]init];
55 | header.refreshingTarget = target;
56 | header.refreshingAction = action;
57 | return header;
58 | }
59 |
60 | - (instancetype)initWithFrame:(CGRect)frame {
61 | self = [super initWithFrame:frame];
62 | if (self) {
63 | [self setupViews];
64 | }
65 | return self;
66 | }
67 |
68 | - (void)setupViews {
69 | self.autoresizingMask = UIViewAutoresizingFlexibleWidth;
70 | self.st_y = - kSTRefreshHeaderHeight;
71 | self.st_height = kSTRefreshHeaderHeight;
72 | self.state = STRefreshStateNormal;
73 | self.colorArray = @[RGBColor(240, 128, 128),
74 | RGBColor(124, 205, 124),
75 | RGBColor(224, 238, 224)];
76 |
77 | // content
78 | self.contentView = [UIView new];
79 | _contentView.st_size = CGSizeMake(kSTRefreshImageWidth, kSTRefreshImageWidth);
80 | _contentView.st_centerY = self.st_height;
81 | _contentView.alpha = 0;
82 |
83 | // image
84 | self.headerImageV = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"github"]];
85 | _headerImageV.frame = _contentView.bounds;
86 | _headerImageV.layer.masksToBounds = YES;
87 |
88 | // circle layer
89 | self.circleLayer = [[CAShapeLayer alloc]init];
90 | _circleLayer.frame = _contentView.bounds;
91 | _circleLayer.fillColor = nil;
92 | _circleLayer.lineWidth = kSTRefreshCircleLineWidth;
93 | _circleLayer.lineCap = kCALineCapRound;
94 | _circleLayer.strokeStart = 0;
95 | _circleLayer.strokeEnd = 0;
96 | _circleLayer.strokeColor = [(UIColor *)_colorArray.firstObject CGColor];
97 |
98 | CGPoint center = CGPointMake(_contentView.st_width / 2.0, _contentView.st_height / 2.0);
99 | CGFloat radius = _contentView.st_height/2.0 - _circleLayer.lineWidth / 2.0;
100 | CGFloat startAngle = -M_PI_2;
101 | CGFloat endAngle = 2*M_PI - M_PI_2;
102 | UIBezierPath *path = [UIBezierPath bezierPathWithArcCenter:center
103 | radius:radius
104 | startAngle:startAngle
105 | endAngle:endAngle
106 | clockwise:YES];
107 | _circleLayer.path = path.CGPath;
108 |
109 | [self addSubview:_contentView];
110 | [_contentView addSubview:_headerImageV];
111 | [_contentView.layer addSublayer:_circleLayer];
112 | }
113 |
114 | - (void)startLoadingAnimation {
115 | if (!_isAnimating) {
116 | [self.circleLayer removeAllAnimations];
117 | }
118 | _isAnimating = YES;
119 |
120 | // Stroke Head
121 | CABasicAnimation *headAnimation1 = [CABasicAnimation animationWithKeyPath:@"strokeStart"];
122 | headAnimation1.fromValue = @0;
123 | headAnimation1.toValue = @0.25;
124 | headAnimation1.duration = kSTRefreshRoundTime/3.0;
125 | headAnimation1.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
126 |
127 | CABasicAnimation *headAnimation2 = [CABasicAnimation animationWithKeyPath:@"strokeStart"];
128 | headAnimation2.beginTime = kSTRefreshRoundTime/3.0;
129 | headAnimation2.fromValue = @0.25;
130 | headAnimation2.toValue = @1;
131 | headAnimation2.duration = 2*kSTRefreshRoundTime/3.0;
132 | headAnimation2.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
133 |
134 | // Stroke Tail
135 | CABasicAnimation *tailAnimation1 = [CABasicAnimation animationWithKeyPath:@"strokeEnd"];
136 | tailAnimation1.fromValue = @0.25;
137 | tailAnimation1.toValue = @0.85;
138 | tailAnimation1.duration = kSTRefreshRoundTime/3.0;
139 | tailAnimation1.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
140 |
141 | CABasicAnimation *tailAnimation2 = [CABasicAnimation animationWithKeyPath:@"strokeEnd"];
142 | tailAnimation2.beginTime = kSTRefreshRoundTime/3.0;
143 | tailAnimation2.fromValue = @0.85;
144 | tailAnimation2.toValue = @1.25;
145 | tailAnimation2.duration = 2*kSTRefreshRoundTime/3.0;
146 | tailAnimation2.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
147 |
148 | // Stroke Line Group
149 | CAAnimationGroup *animationGroup = [CAAnimationGroup animation];
150 | animationGroup.duration = kSTRefreshRoundTime;
151 | animationGroup.repeatCount = INFINITY;
152 | animationGroup.animations = @[headAnimation1, headAnimation2, tailAnimation1, tailAnimation2];
153 |
154 | // Rotation
155 | CABasicAnimation *rotationAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
156 | rotationAnimation.fromValue = @0;
157 | rotationAnimation.toValue = @(2*M_PI);
158 | rotationAnimation.duration = kSTRefreshRoundTime;
159 | rotationAnimation.repeatCount = INFINITY;
160 |
161 | CAKeyframeAnimation *strokeColorAnimation = [CAKeyframeAnimation animationWithKeyPath:@"strokeColor"];
162 | strokeColorAnimation.values = [self prepareColorValues];
163 | strokeColorAnimation.keyTimes = [self prepareKeyTimes];
164 | strokeColorAnimation.calculationMode = kCAAnimationDiscrete;
165 | strokeColorAnimation.duration = self.colorArray.count *kSTRefreshRoundTime;
166 | strokeColorAnimation.repeatCount = INFINITY;
167 |
168 | [self.circleLayer addAnimation:animationGroup forKey:nil];
169 | [self.circleLayer addAnimation:rotationAnimation forKey:nil];
170 | [self.circleLayer addAnimation:strokeColorAnimation forKey:nil];
171 | }
172 |
173 | - (void)stopLoadingAnimation {
174 | if (_isAnimating) {
175 | [self.circleLayer removeAllAnimations];
176 | }
177 | _isAnimating = NO;
178 | [self.circleLayer setStrokeStart:0];
179 | [self.circleLayer setStrokeEnd:1];
180 | [self.circleLayer setStrokeColor:[(UIColor *)_colorArray.firstObject CGColor]];
181 | }
182 |
183 | - (NSArray*)prepareColorValues {
184 | NSMutableArray *cgColorArray = [[NSMutableArray alloc] init];
185 | for(UIColor *color in self.colorArray){
186 | [cgColorArray addObject:(id)color.CGColor];
187 | }
188 | return cgColorArray;
189 | }
190 |
191 | - (NSArray*)prepareKeyTimes {
192 | NSMutableArray *keyTimesArray = [[NSMutableArray alloc] init];
193 | for(NSUInteger i = 0; i < self.colorArray.count + 1; i ++){
194 | [keyTimesArray addObject:[NSNumber numberWithFloat:i *1.0/self.colorArray.count]];
195 | }
196 | return keyTimesArray;
197 | }
198 |
199 |
200 | - (void)willMoveToSuperview:(UIView *)newSuperview {
201 | [super willMoveToSuperview:newSuperview];
202 |
203 | if (newSuperview && ![newSuperview isKindOfClass:[UIScrollView class]]) return;
204 |
205 | [self removeObservers];
206 |
207 | if (nil != newSuperview) {
208 | self.scrollView = (UIScrollView *)newSuperview;
209 | self.st_width = newSuperview.st_width;
210 |
211 | [self setNeedsLayout];
212 | [self layoutIfNeeded];
213 |
214 | [self addObservers];
215 | }
216 | }
217 |
218 | - (void)layoutSubviews {
219 | [super layoutSubviews];
220 | _contentView.st_centerX = self.st_width/2;
221 | }
222 |
223 | - (void)addObservers {
224 | NSKeyValueObservingOptions options = NSKeyValueObservingOptionNew | NSKeyValueObservingOptionOld;
225 | [self.scrollView addObserver:self forKeyPath:@"contentOffset" options:options context:STRefreshContentOffsetContext];
226 | [self.scrollView addObserver:self forKeyPath:@"contentInset" options:options context:STRefreshcontentInsetContext];
227 | }
228 |
229 | - (void)removeObservers {
230 | [self.superview removeObserver:self forKeyPath:@"contentOffset"];
231 | [self.superview removeObserver:self forKeyPath:@"contentInset"];;
232 | }
233 |
234 | #pragma mark - observe
235 |
236 | - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context {
237 | if (context == STRefreshcontentInsetContext) {
238 | if (_state != STRefreshStateRefeshing) {
239 | UIEdgeInsets contentInsets = [change[NSKeyValueChangeNewKey] UIEdgeInsetsValue];
240 | _orginContentInsetTop = contentInsets.top;
241 | }
242 | }
243 |
244 | else if (context == STRefreshContentOffsetContext) {
245 | CGPoint contentOffset = [change[NSKeyValueChangeNewKey] CGPointValue];
246 | CGFloat moveOffsetY = _orginContentInsetTop + contentOffset.y;
247 | if (moveOffsetY > 0) {
248 | return;
249 | }
250 | moveOffsetY = - moveOffsetY;
251 | _contentView.st_centerY = self.st_height - moveOffsetY/2;
252 |
253 | // 拖拽
254 | if (self.scrollView.isDragging) {
255 |
256 | CGFloat pullPercent = fmin(moveOffsetY/kSTRefreshHeaderHeight, 1);
257 | _circleLayer.strokeEnd = pullPercent;
258 | _contentView.alpha = pullPercent;
259 | _headerImageV.transform = CGAffineTransformMakeRotation(pullPercent * (M_PI - 0.001));
260 |
261 | if (self.state == STRefreshStateRefeshing) {
262 | return;
263 | }
264 | self.state = STRefreshStatePulling;
265 |
266 | if (moveOffsetY > kSTRefreshHeaderHeight) {
267 | self.state = STRefreshStateWillRefesh;
268 | }
269 | }
270 | // 松手刷新 或 返回
271 | else {
272 | if (self.state == STRefreshStateWillRefesh) {
273 | [self beganRefreshing];
274 | }else if (self.state != STRefreshStateNormal) {
275 |
276 | CGFloat pullPercent = fmin(moveOffsetY/kSTRefreshHeaderHeight, 1);
277 | _circleLayer.strokeEnd = pullPercent;
278 | _contentView.alpha = pullPercent;
279 | _headerImageV.transform = CGAffineTransformMakeRotation(pullPercent * (M_PI - 0.001));
280 |
281 | }
282 | }
283 | }
284 | }
285 |
286 | - (void)beganRefreshing {
287 | self.state = STRefreshStateRefeshing;
288 | [UIView animateWithDuration:0.25f delay:0 options:UIViewAnimationOptionAllowUserInteraction | UIViewAnimationOptionCurveEaseInOut animations:^{
289 |
290 | self.contentView.st_centerY = self.st_height/2;
291 |
292 | UIEdgeInsets contentInset = self.scrollView.contentInset;
293 | contentInset.top = _orginContentInsetTop + kSTRefreshHeaderHeight;
294 |
295 | self.scrollView.contentInset = contentInset;
296 | self.scrollView.contentOffset = CGPointMake(self.scrollView.contentOffset.x, - contentInset.top);
297 |
298 | } completion:^(BOOL finished) {
299 | [self startLoadingAnimation];
300 | [self executeRefreshingCallback];
301 | }];
302 | }
303 |
304 | - (void)endRefreshing {
305 | if (self.state != STRefreshStateRefeshing) {
306 | return;
307 | }
308 | self.state = STRefreshStateNormal;
309 |
310 | [self stopLoadingAnimation];
311 |
312 | [UIView animateWithDuration:0.5f delay:0 options:UIViewAnimationOptionAllowUserInteraction | UIViewAnimationOptionCurveEaseInOut animations:^{
313 |
314 | UIEdgeInsets contentInset = self.scrollView.contentInset;
315 | contentInset.top -= kSTRefreshHeaderHeight;
316 | self.scrollView.contentInset = contentInset;
317 | self.scrollView.contentOffset = CGPointMake(self.scrollView.contentOffset.x, - contentInset.top);
318 |
319 | self.contentView.st_centerY = self.st_height;
320 | self.contentView.alpha = 0;
321 | self.circleLayer.strokeEnd = 0;
322 | self.headerImageV.transform = CGAffineTransformIdentity;
323 |
324 | } completion:^(BOOL finished) {
325 |
326 | }];
327 | }
328 |
329 | - (void)executeRefreshingCallback {
330 | dispatch_async(dispatch_get_main_queue(), ^{
331 | if (self.refreshingBlock) {
332 | self.refreshingBlock(self);
333 | }
334 | if ([self.refreshingTarget respondsToSelector:self.refreshingAction]) {
335 | ((void (*)(void *, SEL, UIView *))objc_msgSend)((__bridge void *)(self.refreshingTarget),self.refreshingAction, self);
336 | }
337 | });
338 | }
339 |
340 | @end
341 |
342 |
343 |
344 |
345 |
346 |
347 |
--------------------------------------------------------------------------------
/SwipeTableView/SwipeTableViewDemo/STRefresh/UIScrollView+STRefresh.h:
--------------------------------------------------------------------------------
1 | //
2 | // UIScrollView+STRefresh.h
3 | // SwipeTableView
4 | //
5 | // Created by Roy lee on 16/7/10.
6 | // Copyright © 2016年 Roy lee. All rights reserved.
7 | //
8 |
9 | #import
10 | #import "STRefreshHeader.h"
11 |
12 | @interface UIScrollView (STRefresh)
13 |
14 | @property (nonatomic, strong) STRefreshHeader * header;
15 |
16 | @end
17 |
--------------------------------------------------------------------------------
/SwipeTableView/SwipeTableViewDemo/STRefresh/UIScrollView+STRefresh.m:
--------------------------------------------------------------------------------
1 | //
2 | // UIScrollView+STRefresh.m
3 | // SwipeTableView
4 | //
5 | // Created by Roy lee on 16/7/10.
6 | // Copyright © 2016年 Roy lee. All rights reserved.
7 | //
8 |
9 | #import "UIScrollView+STRefresh.h"
10 | #import
11 |
12 | @implementation UIScrollView (STRefresh)
13 |
14 | - (STRefreshHeader *)header {
15 | return objc_getAssociatedObject(self, _cmd);
16 | }
17 |
18 | - (void)setHeader:(STRefreshHeader *)header {
19 | [self.header removeFromSuperview];
20 | [self addSubview:header];
21 |
22 | SEL key = @selector(header);
23 | objc_setAssociatedObject(self, key, header, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
24 | }
25 |
26 | @end
27 |
--------------------------------------------------------------------------------
/SwipeTableView/SwipeTableViewDemo/STRefresh/github.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/liangdrime/SwipeTableView/ffdc47708ca33ee209ae09c9433f71d1463dacc2/SwipeTableView/SwipeTableViewDemo/STRefresh/github.png
--------------------------------------------------------------------------------
/SwipeTableView/SwipeTableViewDemo/STTransition/STTransitions.h:
--------------------------------------------------------------------------------
1 | //
2 | // STTransitions.h
3 | // SwipeTableView
4 | //
5 | // Created by Roy lee on 16/6/24.
6 | // Copyright © 2016年 Roy lee. All rights reserved.
7 | //
8 |
9 | #import
10 | #import
11 |
12 | @interface STTransitions : NSObject
13 |
14 | - (instancetype)initWithTransitionDuration:(NSTimeInterval)transitionDuration fromView:(UIView *)fromView isPresenting:(BOOL)present;
15 |
16 | @end
17 |
--------------------------------------------------------------------------------
/SwipeTableView/SwipeTableViewDemo/STTransition/STTransitions.m:
--------------------------------------------------------------------------------
1 | //
2 | // STTransitions.m
3 | // SwipeTableView
4 | //
5 | // Created by Roy lee on 16/6/24.
6 | // Copyright © 2016年 Roy lee. All rights reserved.
7 | //
8 |
9 | #import "STTransitions.h"
10 | #import "STImageController.h"
11 |
12 | #define kScreenWidth [UIScreen mainScreen].bounds.size.width
13 | #define kScreenHeight [UIScreen mainScreen].bounds.size.height
14 |
15 | @interface UIView (UIImageView)
16 | - (UIImageView *)imageView;
17 | @end
18 |
19 |
20 | @interface STTransitions ()
21 |
22 | @property (nonatomic, assign) NSTimeInterval transitionDuration;
23 | @property (nonatomic, assign) CGFloat startingAlpha;
24 | @property (nonatomic, assign) BOOL isPresenting;
25 | @property (nonatomic, strong) id transitionContext;
26 | @property (nonatomic, strong) UIView * fromView;
27 |
28 | @end
29 |
30 | @implementation STTransitions
31 |
32 | - (instancetype)initWithTransitionDuration:(NSTimeInterval)transitionDuration fromView:(UIView *)fromView isPresenting:(BOOL)present {
33 | self = [super init];
34 | if (self) {
35 | _transitionDuration = transitionDuration;
36 | _isPresenting = present;;
37 | _fromView = fromView;
38 | }
39 | return self;
40 | }
41 |
42 | - (NSTimeInterval)transitionDuration:(id )transitionContext {
43 | return _transitionDuration;
44 | }
45 |
46 | - (void)animateTransition:(id )transitionContext {
47 | UIView *containerView = [transitionContext containerView];
48 | UIViewController * fromVC = [transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey];
49 | UIViewController * toVC = [transitionContext viewControllerForKey:UITransitionContextToViewControllerKey];
50 | UIView * fromView = fromVC.view;
51 | UIView * toView = toVC.view;
52 |
53 | if (_isPresenting) {
54 | STImageController * imageVC = (STImageController *)toVC;
55 | UIImageView * fromImageView = _fromView.imageView;
56 | UIImageView * toImageView = imageVC.imageView;
57 | CGFloat imageH = fromImageView.image.size.height/fromImageView.image.size.width * kScreenWidth;
58 | CGRect toFrame = CGRectMake(0, (kScreenHeight - imageH)/2, kScreenWidth, imageH);
59 | toImageView.image = fromImageView.image;
60 | toImageView.frame = toFrame;
61 | UIImageView * transitionView = [[UIImageView alloc]initWithImage:fromImageView.image];
62 |
63 | fromView.alpha = 1.0f;
64 | toView.alpha = 0.3f;
65 | fromImageView.hidden = YES;
66 | toImageView.hidden = YES;
67 | transitionView.frame = [containerView convertRect:fromImageView.frame fromView:fromImageView.superview];
68 | [containerView addSubview:toVC.view];
69 | [containerView addSubview:transitionView];
70 |
71 | [UIView animateWithDuration:[self transitionDuration:transitionContext] animations:^{
72 | transitionView.frame = [containerView convertRect:toFrame fromView:toImageView.superview];
73 | fromView.alpha = 0.0f;
74 | toView.alpha = 1.0f;
75 | } completion:^(BOOL finished) {
76 | toImageView.hidden = NO;
77 | [transitionView removeFromSuperview];
78 | [transitionContext completeTransition:YES];
79 | }];
80 | }else {
81 | STImageController * imageVC = (STImageController *)fromVC;
82 | UIImageView * fromImageView = imageVC.imageView;
83 | UIImageView * toImageView = _fromView.imageView;
84 | UIImageView * transitionView = [[UIImageView alloc]initWithImage:fromImageView.image];
85 |
86 | fromView.alpha = 1.0f;
87 | toView.alpha = 0;
88 | fromImageView.hidden = YES;
89 | toImageView.hidden = YES;
90 | transitionView.frame = [containerView convertRect:fromImageView.frame fromView:fromImageView.superview];
91 | [containerView addSubview:toVC.view];
92 | [containerView addSubview:transitionView];
93 |
94 | [UIView animateWithDuration:[self transitionDuration:transitionContext] animations:^{
95 | transitionView.frame = [containerView convertRect:toImageView.frame fromView:toImageView.superview];
96 | fromView.alpha = 0.0f;
97 | toView.alpha = 1.0f;
98 |
99 | } completion:^(BOOL finished) {
100 | toImageView.hidden = NO;
101 | [transitionView removeFromSuperview];
102 | [transitionContext completeTransition:YES];
103 | }];
104 | }
105 | }
106 |
107 |
108 | @end
109 |
110 |
111 | @implementation UIView (UIImageView)
112 |
113 | - (UIImageView *)imageView {
114 | if ([self isKindOfClass:UIImageView.class]) {
115 | return (UIImageView *)self;
116 | }
117 | for (UIView * subView in self.subviews) {
118 | if ([subView isKindOfClass:UIImageView.class]) {
119 | return (UIImageView *)subView;
120 | }
121 | }
122 | return nil;
123 | }
124 |
125 | @end
126 |
127 |
--------------------------------------------------------------------------------
/SwipeTableView/SwipeTableViewDemo/STView/CustomCollectionView.h:
--------------------------------------------------------------------------------
1 | //
2 | // CustomCollectionView.h
3 | // SwipeTableView
4 | //
5 | // Created by Roy lee on 16/4/1.
6 | // Copyright © 2016年 Roy lee. All rights reserved.
7 | //
8 |
9 | #import
10 | #import "STCollectionView.h"
11 |
12 | #define kScreenWidth [UIScreen mainScreen].bounds.size.width
13 | #define kScreenHeight [UIScreen mainScreen].bounds.size.height
14 |
15 | @interface CustomCollectionView : STCollectionView
16 |
17 | - (void)refreshWithData:(id)data atIndex:(NSInteger)index;
18 |
19 | @end
20 |
--------------------------------------------------------------------------------
/SwipeTableView/SwipeTableViewDemo/STView/CustomCollectionView.m:
--------------------------------------------------------------------------------
1 | //
2 | // CustomCollectionView.m
3 | // SwipeTableView
4 | //
5 | // Created by Roy lee on 16/4/1.
6 | // Copyright © 2016年 Roy lee. All rights reserved.
7 | //
8 |
9 | #import "CustomCollectionView.h"
10 | #import "UIView+STFrame.h"
11 | #import "STRefresh.h"
12 |
13 | #define RGBColor(r,g,b) [UIColor colorWithRed:r/255.0 green:g/255.0 blue:b/255.0 alpha:1]
14 |
15 | @interface CustomCollectionView ()
16 |
17 | @property (nonatomic, strong) NSMutableArray * itemSizes;
18 | @property (nonatomic, assign) NSInteger numberOfItems;
19 | @property (nonatomic, assign) BOOL isWaterFlow;
20 |
21 | @end
22 | @implementation CustomCollectionView
23 |
24 | - (instancetype)initWithFrame:(CGRect)frame {
25 |
26 | self = [super initWithFrame:frame];
27 | if (self) {
28 | [self commonInit];
29 | }
30 | return self;
31 | }
32 |
33 | - (instancetype)initWithFrame:(CGRect)frame collectionViewLayout:(UICollectionViewLayout *)_layout {
34 | self = [super initWithFrame:frame collectionViewLayout:_layout];
35 | if (self) {
36 | [self commonInit];
37 | }
38 | return self;
39 | }
40 |
41 | - (void)commonInit {
42 | STCollectionViewFlowLayout * layout = self.st_collectionViewLayout;
43 | layout.minimumInteritemSpacing = 5;
44 | layout.minimumLineSpacing = 5;
45 | layout.sectionInset = UIEdgeInsetsMake(5, 5, 5, 5);
46 | self.stDelegate = self;
47 | self.stDataSource = self;
48 | [self registerClass:UICollectionViewCell.class forCellWithReuseIdentifier:@"item"];
49 | [self registerClass:UICollectionReusableView.class forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"header"];
50 | [self registerClass:UICollectionReusableView.class forSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:@"footer"];
51 |
52 | self.header = [STRefreshHeader headerWithRefreshingBlock:^(STRefreshHeader *header) {
53 | dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
54 | [header endRefreshing];
55 | });
56 | }];
57 | }
58 |
59 | - (NSMutableArray *)itemSizes {
60 | if (nil == _itemSizes) {
61 | _itemSizes = [NSMutableArray array];
62 | [_itemSizes addObject:[NSValue valueWithCGSize:CGSizeMake(100, 100)]];
63 | [_itemSizes addObject:[NSValue valueWithCGSize:CGSizeMake(100, 80)]];
64 | [_itemSizes addObject:[NSValue valueWithCGSize:CGSizeMake(100, 70)]];
65 | [_itemSizes addObject:[NSValue valueWithCGSize:CGSizeMake(100, 90)]];
66 |
67 | // [_itemSizes addObject:[NSValue valueWithCGSize:CGSizeMake(100, 100)]];
68 | // [_itemSizes addObject:[NSValue valueWithCGSize:CGSizeMake(100, 100)]];
69 | // [_itemSizes addObject:[NSValue valueWithCGSize:CGSizeMake(100, 100)]];
70 | // [_itemSizes addObject:[NSValue valueWithCGSize:CGSizeMake(100, 100)]];
71 |
72 | }
73 | return _itemSizes;
74 | }
75 |
76 | - (void)refreshWithData:(id)numberOfItems atIndex:(NSInteger)index {
77 | _numberOfItems = [numberOfItems integerValue];
78 | _isWaterFlow = index == 1;
79 |
80 | NSLog(@"data === %ld index === %ld isWaterFlow === %d",[numberOfItems integerValue],index,_isWaterFlow);
81 |
82 | [self reloadData];
83 | }
84 |
85 |
86 | #pragma mark - STCollectionView M
87 |
88 | - (NSInteger)collectionView:(UICollectionView *)collectionView layout:(STCollectionViewFlowLayout *)layout numberOfColumnsInSection:(NSInteger)section {
89 | return 4;
90 | }
91 |
92 | - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
93 | if (_isWaterFlow) {
94 | return [[self.itemSizes objectAtIndex:indexPath.row % 4] CGSizeValue];
95 | }
96 | return CGSizeMake(0, 100);
97 | }
98 |
99 | - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section {
100 | if (_numberOfItems <= 0) {
101 | return CGSizeZero;
102 | }
103 | return CGSizeMake(kScreenWidth, 35);
104 | }
105 |
106 | - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout referenceSizeForFooterInSection:(NSInteger)section {
107 | if (_numberOfItems <= 0) {
108 | return CGSizeZero;
109 | }
110 | return CGSizeMake(kScreenWidth, 35);
111 | }
112 |
113 | - (UICollectionReusableView *)stCollectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath {
114 |
115 | UICollectionReusableView * reusableView = nil;
116 | if ([kind isEqualToString:UICollectionElementKindSectionHeader]) {
117 | reusableView = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"header" forIndexPath:indexPath];
118 | UILabel * title = [reusableView viewWithTag:777];
119 | if (nil == title) {
120 | title = [UILabel new];
121 | title.tag = 777;
122 | title.backgroundColor = RGBColor(113, 198, 113);
123 | title.textColor = [UIColor whiteColor];
124 | title.font = [UIFont systemFontOfSize:16];
125 | title.textAlignment = NSTextAlignmentCenter;
126 | [reusableView addSubview:title];
127 | }
128 | title.frame = reusableView.bounds;
129 | title.text = [NSString stringWithFormat:@"Header %ld",indexPath.section];
130 | }else if ([kind isEqualToString:UICollectionElementKindSectionFooter]) {
131 | reusableView = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:@"footer" forIndexPath:indexPath];
132 | UILabel * footer = [reusableView viewWithTag:999];
133 | if (nil == footer) {
134 | footer = [UILabel new];
135 | footer.tag = 999;
136 | footer.backgroundColor = RGBColor(197, 193, 170);
137 | footer.textColor = [UIColor whiteColor];
138 | footer.font = [UIFont systemFontOfSize:16];
139 | footer.textAlignment = NSTextAlignmentCenter;
140 | [reusableView addSubview:footer];
141 | }
142 | footer.frame = reusableView.bounds;
143 | footer.text = [NSString stringWithFormat:@"Footer %ld",indexPath.section];
144 | }
145 | return reusableView;
146 | }
147 |
148 | - (NSInteger)numberOfSectionsInStCollectionView:(UICollectionView *)collectionView {
149 | if (_numberOfItems <= 0) {
150 | return 0;
151 | }
152 | return 2;
153 | }
154 |
155 | - (NSInteger)stCollectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
156 | return _numberOfItems;
157 | }
158 |
159 | - (UICollectionViewCell *)stCollectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
160 | UICollectionViewCell * cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"item" forIndexPath:indexPath];
161 | cell.backgroundColor = RGBColor(150, 215, 200);
162 | // title
163 | UILabel * title = [cell viewWithTag:888];
164 | if (nil == title) {
165 | title = [UILabel new];
166 | title.tag = 888;
167 | title.st_size = CGSizeMake(80, 40);
168 | title.textColor = [UIColor whiteColor];
169 | title.textAlignment = NSTextAlignmentCenter;
170 | title.font = [UIFont systemFontOfSize:16];
171 | [cell addSubview:title];
172 | }
173 | title.center = CGPointMake(cell.st_width/2, cell.st_height/2);
174 | title.text = [NSString stringWithFormat:@"Item %ld",indexPath.item];
175 | return cell;
176 | }
177 |
178 | @end
179 |
--------------------------------------------------------------------------------
/SwipeTableView/SwipeTableViewDemo/STView/CustomSegmentControl.h:
--------------------------------------------------------------------------------
1 | //
2 | // CustomSegmentControl.h
3 | // SwipeTableView
4 | //
5 | // Created by Roy lee on 16/5/28.
6 | // Copyright © 2016年 Roy lee. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | @interface CustomSegmentControl : UIControl
12 |
13 | @property (nonatomic, strong) UIFont *font;
14 | @property (nonatomic, strong) UIColor *textColor;
15 | @property (nonatomic, strong) UIColor *selectedTextColor;
16 | @property (nonatomic, strong) UIColor *backgroundColor;
17 | @property (nonatomic, strong) UIColor *selectionIndicatorColor;
18 | @property (nonatomic, assign) NSInteger selectedSegmentIndex;
19 | @property (nonatomic, copy) void (^IndexChangeBlock)(NSInteger index);
20 |
21 | - (instancetype)initWithItems:(NSArray *)items;
22 |
23 | @end
24 |
--------------------------------------------------------------------------------
/SwipeTableView/SwipeTableViewDemo/STView/CustomSegmentControl.m:
--------------------------------------------------------------------------------
1 | //
2 | // CustomSegmentControl.m
3 | // SwipeTableView
4 | //
5 | // Created by Roy lee on 16/5/28.
6 | // Copyright © 2016年 Roy lee. All rights reserved.
7 | //
8 |
9 | #import "CustomSegmentControl.h"
10 | #import "UIView+STFrame.h"
11 | #define RGBColor(r,g,b) [UIColor colorWithRed:r/255.0 green:g/255.0 blue:b/255.0 alpha:1]
12 |
13 | @interface CustomSegmentControl ()
14 |
15 | @property (nonatomic, strong) UIView * contentView;
16 | @property (nonatomic, strong) NSArray * items;
17 |
18 | @end
19 |
20 | @implementation CustomSegmentControl
21 |
22 | - (instancetype)initWithFrame:(CGRect)frame {
23 | self = [super initWithFrame:frame];
24 | if (self) {
25 | [self commonInit];
26 | }
27 | return self;
28 | }
29 |
30 | - (instancetype)initWithItems:(NSArray *)items {
31 | self = [self initWithFrame:CGRectZero];
32 | if (self) {
33 | if (items.count > 0) {
34 | self.items = items;
35 | }
36 | }
37 | return self;
38 | }
39 |
40 | - (void)commonInit {
41 | _contentView = [UIView new];
42 | _contentView.backgroundColor = [UIColor whiteColor];
43 | [self addSubview:_contentView];
44 | _font = [UIFont systemFontOfSize:15];
45 | _textColor = RGBColor(50, 50, 50);
46 | _selectedTextColor = RGBColor(0, 0, 0);
47 | _selectionIndicatorColor = RGBColor(150, 150, 150);
48 | _items = @[@"Segment0",@"Segment1"];
49 | _selectedSegmentIndex = 0;
50 | }
51 |
52 | - (void)layoutSubviews {
53 | [super layoutSubviews];
54 | for (UIView *subView in _contentView.subviews) {
55 | [subView removeFromSuperview];
56 | }
57 |
58 | _contentView.backgroundColor = _backgroundColor;
59 | _contentView.frame = self.bounds;
60 | for (int i = 0; i < _items.count; i ++) {
61 | UIButton * itemBt = [UIButton buttonWithType:UIButtonTypeCustom];
62 | itemBt.tag = 666 + i;
63 | [itemBt setTitleColor:_textColor forState:UIControlStateNormal];
64 | [itemBt setTitleColor:_selectedTextColor forState:UIControlStateSelected];
65 | [itemBt setTitle:_items[i] forState:UIControlStateNormal];
66 | [itemBt.titleLabel setFont:_font];
67 | CGFloat itemWidth = self.st_width/_items.count;
68 | itemBt.st_size = CGSizeMake(itemWidth, self.st_height);
69 | itemBt.st_x = itemWidth * i;
70 | if (i == _selectedSegmentIndex) {
71 | itemBt.backgroundColor = _selectionIndicatorColor;
72 | itemBt.selected = YES;
73 | }else {
74 | itemBt.backgroundColor = [UIColor clearColor];
75 | }
76 | [itemBt addTarget:self action:@selector(didSelectedSegment:) forControlEvents:UIControlEventTouchUpInside];
77 | [_contentView addSubview:itemBt];
78 | }
79 | }
80 |
81 | - (void)setSelectedSegmentIndex:(NSInteger)selectedSegmentIndex {
82 | UIButton * oldItemBt = [_contentView viewWithTag:666 + _selectedSegmentIndex];
83 | oldItemBt.backgroundColor = [UIColor clearColor];
84 | oldItemBt.selected = NO;
85 |
86 | UIButton * itemBt = [_contentView viewWithTag:666 + selectedSegmentIndex];
87 | itemBt.backgroundColor = _selectionIndicatorColor;
88 | itemBt.selected = YES;
89 | _selectedSegmentIndex = selectedSegmentIndex;
90 | }
91 |
92 | - (void)didSelectedSegment:(UIButton *)itemBt {
93 | UIButton * oldItemBt = [_contentView viewWithTag:666 + _selectedSegmentIndex];
94 | oldItemBt.backgroundColor = [UIColor clearColor];
95 | oldItemBt.selected = NO;
96 |
97 | itemBt.backgroundColor = _selectionIndicatorColor;
98 | itemBt.selected = YES;
99 | _selectedSegmentIndex = itemBt.tag - 666;
100 | if (self.IndexChangeBlock) {
101 | self.IndexChangeBlock(_selectedSegmentIndex);
102 | }
103 | [self sendActionsForControlEvents:UIControlEventValueChanged];
104 | }
105 |
106 | @end
107 |
108 |
109 |
110 |
111 |
112 |
--------------------------------------------------------------------------------
/SwipeTableView/SwipeTableViewDemo/STView/CustomTableView.h:
--------------------------------------------------------------------------------
1 | //
2 | // CustomTableView.h
3 | // SwipeTableView
4 | //
5 | // Created by Roy lee on 16/4/1.
6 | // Copyright © 2016年 Roy lee. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | @interface CustomTableView : UITableView
12 |
13 | - (void)refreshWithData:(id)data atIndex:(NSInteger)index;
14 |
15 | @end
16 |
--------------------------------------------------------------------------------
/SwipeTableView/SwipeTableViewDemo/STView/CustomTableView.m:
--------------------------------------------------------------------------------
1 | //
2 | // CustomTableView.m
3 | // SwipeTableView
4 | //
5 | // Created by Roy lee on 16/4/1.
6 | // Copyright © 2016年 Roy lee. All rights reserved.
7 | //
8 |
9 | #import "CustomTableView.h"
10 | #import "UIView+STFrame.h"
11 | #import "STRefresh.h"
12 | #import "SwipeTableView.h"
13 |
14 | #define RGBColor(r,g,b) [UIColor colorWithRed:r/255.0 green:g/255.0 blue:b/255.0 alpha:1]
15 |
16 | @interface CustomTableView ()
17 |
18 | @property (nonatomic, assign) NSInteger itemIndex;
19 | @property (nonatomic, assign) NSInteger numberOfRows;
20 |
21 | @end
22 |
23 | @implementation CustomTableView
24 |
25 | - (instancetype)initWithFrame:(CGRect)frame style:(UITableViewStyle)style {
26 | self = [super initWithFrame:frame style:style];
27 | if (self) {
28 | self.delegate = self;
29 | self.dataSource = self;
30 | self.separatorColor = RGBColor(175, 175, 175);
31 | [self registerClass:UITableViewCell.class forCellReuseIdentifier:@"cell"];
32 | self.tableFooterView = [UIView new];
33 | self.itemIndex = -1;
34 |
35 | self.header = [STRefreshHeader headerWithRefreshingBlock:^(STRefreshHeader *header) {
36 | dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
37 | [header endRefreshing];
38 | });
39 | }];
40 | }
41 | return self;
42 | }
43 |
44 | - (void)refreshWithData:(id)numberOfRows atIndex:(NSInteger)index {
45 | _numberOfRows = [numberOfRows integerValue];
46 | _itemIndex = index;
47 |
48 | [self reloadData];
49 | }
50 |
51 | #pragma mark - UITableView M
52 | - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
53 | return _numberOfRows;
54 | }
55 |
56 | - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
57 | return 60;
58 | }
59 |
60 | - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
61 | UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
62 | cell.backgroundColor = RGBColor(150, 215, 200);
63 | cell.selectionStyle = UITableViewCellSelectionStyleNone;
64 | NSString * title = nil;
65 | if (_itemIndex >= 0) {
66 | title = [NSString stringWithFormat:@"[ ItemView_%ld ] ---- 第 %ld 行",_itemIndex,indexPath.row];
67 | }else {
68 | title = [NSString stringWithFormat:@"第 %ld 行",indexPath.row];
69 | }
70 | cell.textLabel.text = title;
71 | cell.textLabel.textColor = [UIColor whiteColor];
72 | return cell;
73 | }
74 |
75 | - (void)scrollViewDidScroll:(UIScrollView *)scrollView {
76 | #if !defined(ST_PULLTOREFRESH_HEADER_HEIGHT)
77 | STRefreshHeader * header = self.header;
78 | CGFloat orginY = - (header.st_height + self.swipeTableView.swipeHeaderView.st_height + self.swipeTableView.swipeHeaderBar.st_height);
79 | if (header.st_y != orginY) {
80 | header.st_y = orginY;
81 | }
82 | #endif
83 | }
84 |
85 | @end
86 |
--------------------------------------------------------------------------------
/SwipeTableView/SwipeTableViewDemo/onepiece_kiudai.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/liangdrime/SwipeTableView/ffdc47708ca33ee209ae09c9433f71d1463dacc2/SwipeTableView/SwipeTableViewDemo/onepiece_kiudai.png
--------------------------------------------------------------------------------
/SwipeTableView/main.m:
--------------------------------------------------------------------------------
1 | //
2 | // main.m
3 | // SwipeTableView
4 | //
5 | // Created by Roy lee on 16/4/1.
6 | // Copyright © 2016年 Roy lee. All rights reserved.
7 | //
8 |
9 | #import
10 | #import "AppDelegate.h"
11 |
12 | int main(int argc, char * argv[]) {
13 | @autoreleasepool {
14 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/SwipeTableViewTests/Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | en
7 | CFBundleExecutable
8 | $(EXECUTABLE_NAME)
9 | CFBundleIdentifier
10 | $(PRODUCT_BUNDLE_IDENTIFIER)
11 | CFBundleInfoDictionaryVersion
12 | 6.0
13 | CFBundleName
14 | $(PRODUCT_NAME)
15 | CFBundlePackageType
16 | BNDL
17 | CFBundleShortVersionString
18 | 1.0
19 | CFBundleSignature
20 | ????
21 | CFBundleVersion
22 | 1
23 |
24 |
25 |
--------------------------------------------------------------------------------
/SwipeTableViewTests/SwipeTableViewTests.m:
--------------------------------------------------------------------------------
1 | //
2 | // SwipeTableViewTests.m
3 | // SwipeTableViewTests
4 | //
5 | // Created by Roy lee on 16/4/1.
6 | // Copyright © 2016年 Roy lee. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | @interface SwipeTableViewTests : XCTestCase
12 |
13 | @end
14 |
15 | @implementation SwipeTableViewTests
16 |
17 | - (void)setUp {
18 | [super setUp];
19 | // Put setup code here. This method is called before the invocation of each test method in the class.
20 | }
21 |
22 | - (void)tearDown {
23 | // Put teardown code here. This method is called after the invocation of each test method in the class.
24 | [super tearDown];
25 | }
26 |
27 | - (void)testExample {
28 | // This is an example of a functional test case.
29 | // Use XCTAssert and related functions to verify your tests produce the correct results.
30 | }
31 |
32 | - (void)testPerformanceExample {
33 | // This is an example of a performance test case.
34 | [self measureBlock:^{
35 | // Put the code you want to measure the time of here.
36 | }];
37 | }
38 |
39 | @end
40 |
--------------------------------------------------------------------------------