口袋版本的一折买

NewPagedFlowView.m 31KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825
  1. //
  2. // NewPagedFlowView.m
  3. // dianshang
  4. //
  5. // Created by sskh on 16/7/13.
  6. // Copyright © 2016年 Mars. All rights reserved.
  7. // Designed By PageGuo,
  8. // QQ:799573715
  9. // github:https://github.com/PageGuo/NewPagedFlowView
  10. #import "NewPagedFlowView.h"
  11. @interface NewPagedFlowView ()
  12. @property (nonatomic, assign, readwrite) NSInteger currentPageIndex;
  13. /**
  14. * 计时器用到的页数
  15. */
  16. @property (nonatomic, assign) NSInteger page;
  17. /**
  18. * 一页的尺寸
  19. */
  20. @property (nonatomic,assign) CGSize pageSize;
  21. @end
  22. //子控制器的类名
  23. static NSString *subviewClassName;
  24. @implementation NewPagedFlowView
  25. ////////////////////////////////////////////////////////////////////////////////////////////////////
  26. #pragma mark -
  27. #pragma mark Private Methods
  28. - (void)initialize{
  29. self.clipsToBounds = YES;
  30. self.needsReload = YES;
  31. self.pageCount = 0;
  32. self.isOpenAutoScroll = YES;
  33. self.isCarousel = YES;
  34. self.leftRightMargin = 20;
  35. self.topBottomMargin = 30;
  36. _currentPageIndex = 0;
  37. _minimumPageAlpha = 1.0;
  38. _autoTime = 5.0;
  39. self.visibleRange = NSMakeRange(0, 0);
  40. self.reusableCells = [[NSMutableArray alloc] initWithCapacity:0];
  41. self.cells = [[NSMutableArray alloc] initWithCapacity:0];
  42. self.scrollView = [[UIScrollView alloc] initWithFrame:self.bounds];
  43. self.scrollView.scrollsToTop = NO;
  44. self.scrollView.delegate = self;
  45. self.scrollView.pagingEnabled = YES;
  46. self.scrollView.clipsToBounds = NO;
  47. self.scrollView.showsHorizontalScrollIndicator = NO;
  48. self.scrollView.showsVerticalScrollIndicator = NO;
  49. subviewClassName = @"PGIndexBannerSubiew";
  50. [self addSubview:self.scrollView];
  51. }
  52. - (void)setLeftRightMargin:(CGFloat)leftRightMargin {
  53. _leftRightMargin = leftRightMargin * 0.5;
  54. }
  55. - (void)setTopBottomMargin:(CGFloat)topBottomMargin {
  56. _topBottomMargin = topBottomMargin * 0.5;
  57. }
  58. - (void)startTimer {
  59. if (self.orginPageCount > 1 && self.isOpenAutoScroll && self.isCarousel) {
  60. NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:self.autoTime target:self selector:@selector(autoNextPage) userInfo:nil repeats:YES];
  61. self.timer = timer;
  62. [[NSRunLoop mainRunLoop] addTimer:timer forMode:NSRunLoopCommonModes];
  63. }
  64. }
  65. - (void)stopTimer {
  66. if (self.timer) {
  67. [self.timer invalidate];
  68. self.timer = nil;
  69. }
  70. }
  71. - (void)adjustCenterSubview {
  72. if (self.isOpenAutoScroll && self.orginPageCount > 0) {
  73. [_scrollView setContentOffset:CGPointMake(_pageSize.width * self.page, 0) animated:NO];
  74. }
  75. }
  76. #pragma mark --自动轮播
  77. - (void)autoNextPage {
  78. self.page ++;
  79. switch (self.orientation) {
  80. case NewPagedFlowViewOrientationHorizontal:{
  81. [_scrollView setContentOffset:CGPointMake(self.page * _pageSize.width, 0) animated:YES];
  82. break;
  83. }
  84. case NewPagedFlowViewOrientationVertical:{
  85. [_scrollView setContentOffset:CGPointMake(0, self.page * _pageSize.height) animated:YES];
  86. break;
  87. }
  88. default:
  89. break;
  90. }
  91. }
  92. - (void)queueReusableCell:(PGIndexBannerSubiew *)cell{
  93. [_reusableCells addObject:cell];
  94. }
  95. - (void)removeCellAtIndex:(NSInteger)index{
  96. PGIndexBannerSubiew *cell = [_cells objectAtIndex:index];
  97. if ((NSObject *)cell == [NSNull null]) {
  98. return;
  99. }
  100. [self queueReusableCell:cell];
  101. if (cell.superview) {
  102. [cell removeFromSuperview];
  103. }
  104. [_cells replaceObjectAtIndex:index withObject:[NSNull null]];
  105. }
  106. - (void)refreshVisibleCellAppearance{
  107. if (_minimumPageAlpha == 1.0 && self.leftRightMargin == 0 && self.topBottomMargin == 0) {
  108. return;//无需更新
  109. }
  110. switch (self.orientation) {
  111. case NewPagedFlowViewOrientationHorizontal:{
  112. CGFloat offset = _scrollView.contentOffset.x;
  113. for (NSInteger i = self.visibleRange.location; i < self.visibleRange.location + _visibleRange.length; i++) {
  114. PGIndexBannerSubiew *cell = [_cells objectAtIndex:i];
  115. subviewClassName = NSStringFromClass([cell class]);
  116. CGFloat origin = cell.frame.origin.x;
  117. CGFloat delta = fabs(origin - offset);
  118. CGRect originCellFrame = CGRectMake(_pageSize.width * i, 0, _pageSize.width, _pageSize.height);//如果没有缩小效果的情况下的本该的Frame
  119. if (delta < _pageSize.width) {
  120. cell.coverView.alpha = (delta / _pageSize.width) * _minimumPageAlpha;
  121. CGFloat leftRightInset = self.leftRightMargin * delta / _pageSize.width;
  122. CGFloat topBottomInset = self.topBottomMargin * delta / _pageSize.width;
  123. cell.layer.transform = CATransform3DMakeScale((_pageSize.width-leftRightInset*2)/_pageSize.width,(_pageSize.height-topBottomInset*2)/_pageSize.height, 1.0);
  124. cell.frame = UIEdgeInsetsInsetRect(originCellFrame, UIEdgeInsetsMake(topBottomInset, leftRightInset, topBottomInset, leftRightInset));
  125. } else {
  126. cell.coverView.alpha = _minimumPageAlpha;
  127. cell.layer.transform = CATransform3DMakeScale((_pageSize.width-self.leftRightMargin*2)/_pageSize.width,(_pageSize.height-self.topBottomMargin*2)/_pageSize.height, 1.0);
  128. cell.frame = UIEdgeInsetsInsetRect(originCellFrame, UIEdgeInsetsMake(self.topBottomMargin, self.leftRightMargin, self.topBottomMargin, self.leftRightMargin));
  129. }
  130. }
  131. break;
  132. }
  133. case NewPagedFlowViewOrientationVertical:{
  134. CGFloat offset = _scrollView.contentOffset.y;
  135. for (NSInteger i = self.visibleRange.location; i < self.visibleRange.location + _visibleRange.length; i++) {
  136. PGIndexBannerSubiew *cell = [_cells objectAtIndex:i];
  137. subviewClassName = NSStringFromClass([cell class]);
  138. CGFloat origin = cell.frame.origin.y;
  139. CGFloat delta = fabs(origin - offset);
  140. CGRect originCellFrame = CGRectMake(0, _pageSize.height * i, _pageSize.width, _pageSize.height);//如果没有缩小效果的情况下的本该的Frame
  141. if (delta < _pageSize.height) {
  142. cell.coverView.alpha = (delta / _pageSize.height) * _minimumPageAlpha;
  143. CGFloat leftRightInset = self.leftRightMargin * delta / _pageSize.height;
  144. CGFloat topBottomInset = self.topBottomMargin * delta / _pageSize.height;
  145. cell.layer.transform = CATransform3DMakeScale((_pageSize.width-leftRightInset*2)/_pageSize.width,(_pageSize.height-topBottomInset*2) / _pageSize.height, 1.0);
  146. cell.frame = UIEdgeInsetsInsetRect(originCellFrame, UIEdgeInsetsMake(topBottomInset, leftRightInset, topBottomInset, leftRightInset));
  147. cell.mainImageView.frame = cell.bounds;
  148. } else {
  149. cell.coverView.alpha = _minimumPageAlpha;
  150. cell.frame = UIEdgeInsetsInsetRect(originCellFrame, UIEdgeInsetsMake(self.topBottomMargin, self.leftRightMargin, self.topBottomMargin, self.leftRightMargin));
  151. cell.mainImageView.frame = cell.bounds;
  152. }
  153. }
  154. }
  155. default:
  156. break;
  157. }
  158. }
  159. - (void)setPageAtIndex:(NSInteger)pageIndex{
  160. NSParameterAssert(pageIndex >= 0 && pageIndex < [_cells count]);
  161. PGIndexBannerSubiew *cell = [_cells objectAtIndex:pageIndex];
  162. if ((NSObject *)cell == [NSNull null]) {
  163. cell = [_dataSource flowView:self cellForPageAtIndex:pageIndex % self.orginPageCount];
  164. NSAssert(cell!=nil, @"datasource must not return nil");
  165. [_cells replaceObjectAtIndex:pageIndex withObject:cell];
  166. cell.tag = pageIndex % self.orginPageCount;
  167. [cell setSubviewsWithSuperViewBounds:CGRectMake(0, 0, _pageSize.width, _pageSize.height)];
  168. __weak __typeof(self) weakSelf = self;
  169. cell.didSelectCellBlock = ^(NSInteger tag, PGIndexBannerSubiew *cell) {
  170. [weakSelf singleCellTapAction:tag withCell:cell];
  171. };
  172. switch (self.orientation) {
  173. case NewPagedFlowViewOrientationHorizontal:
  174. cell.frame = CGRectMake(_pageSize.width * pageIndex, 0, _pageSize.width, _pageSize.height);
  175. break;
  176. case NewPagedFlowViewOrientationVertical:
  177. cell.frame = CGRectMake(0, _pageSize.height * pageIndex, _pageSize.width, _pageSize.height);
  178. break;
  179. default:
  180. break;
  181. }
  182. if (!cell.superview) {
  183. [_scrollView addSubview:cell];
  184. }
  185. }
  186. }
  187. - (void)setPagesAtContentOffset:(CGPoint)offset{
  188. //计算_visibleRange
  189. CGPoint startPoint = CGPointMake(offset.x - _scrollView.frame.origin.x, offset.y - _scrollView.frame.origin.y);
  190. CGPoint endPoint = CGPointMake(startPoint.x + self.bounds.size.width, startPoint.y + self.bounds.size.height);
  191. switch (self.orientation) {
  192. case NewPagedFlowViewOrientationHorizontal:{
  193. NSInteger startIndex = 0;
  194. for (int i =0; i < [_cells count]; i++) {
  195. if (_pageSize.width * (i +1) > startPoint.x) {
  196. startIndex = i;
  197. break;
  198. }
  199. }
  200. NSInteger endIndex = startIndex;
  201. for (NSInteger i = startIndex; i < [_cells count]; i++) {
  202. //如果都不超过则取最后一个
  203. if ((_pageSize.width * (i + 1) < endPoint.x && _pageSize.width * (i + 2) >= endPoint.x) || i+ 2 == [_cells count]) {
  204. endIndex = i + 1;//i+2 是以个数,所以其index需要减去1
  205. break;
  206. }
  207. }
  208. //可见页分别向前向后扩展一个,提高效率
  209. startIndex = MAX(startIndex - 1, 0);
  210. endIndex = MIN(endIndex + 1, [_cells count] - 1);
  211. // self.visibleRange.location = startIndex;
  212. // self.visibleRange.length = endIndex - startIndex + 1;
  213. self.visibleRange = NSMakeRange(startIndex, endIndex - startIndex + 1);
  214. for (NSInteger i = startIndex; i <= endIndex; i++) {
  215. [self setPageAtIndex:i];
  216. }
  217. for (int i = 0; i < startIndex; i ++) {
  218. [self removeCellAtIndex:i];
  219. }
  220. for (NSInteger i = endIndex + 1; i < [_cells count]; i ++) {
  221. [self removeCellAtIndex:i];
  222. }
  223. break;
  224. }
  225. case NewPagedFlowViewOrientationVertical:{
  226. NSInteger startIndex = 0;
  227. for (int i =0; i < [_cells count]; i++) {
  228. if (_pageSize.height * (i +1) > startPoint.y) {
  229. startIndex = i;
  230. break;
  231. }
  232. }
  233. NSInteger endIndex = startIndex;
  234. for (NSInteger i = startIndex; i < [_cells count]; i++) {
  235. //如果都不超过则取最后一个
  236. if ((_pageSize.height * (i + 1) < endPoint.y && _pageSize.height * (i + 2) >= endPoint.y) || i+ 2 == [_cells count]) {
  237. endIndex = i + 1;//i+2 是以个数,所以其index需要减去1
  238. break;
  239. }
  240. }
  241. //可见页分别向前向后扩展一个,提高效率
  242. startIndex = MAX(startIndex - 1, 0);
  243. endIndex = MIN(endIndex + 1, [_cells count] - 1);
  244. _visibleRange.location = startIndex;
  245. _visibleRange.length = endIndex - startIndex + 1;
  246. for (NSInteger i = startIndex; i <= endIndex; i++) {
  247. [self setPageAtIndex:i];
  248. }
  249. for (NSInteger i = 0; i < startIndex; i ++) {
  250. [self removeCellAtIndex:i];
  251. }
  252. for (NSInteger i = endIndex + 1; i < [_cells count]; i ++) {
  253. [self removeCellAtIndex:i];
  254. }
  255. break;
  256. }
  257. default:
  258. break;
  259. }
  260. }
  261. ////////////////////////////////////////////////////////////////////////////////////////////////////
  262. #pragma mark -
  263. #pragma mark Override Methods
  264. - (id)initWithFrame:(CGRect)frame
  265. {
  266. self = [super initWithFrame:frame];
  267. if (self)
  268. {
  269. [self initialize];
  270. }
  271. return self;
  272. }
  273. - (id)initWithCoder:(NSCoder *)aDecoder
  274. {
  275. self = [super initWithCoder:aDecoder];
  276. if (self)
  277. {
  278. [self initialize];
  279. }
  280. return self;
  281. }
  282. ////////////////////////////////////////////////////////////////////////////////////////////////////
  283. #pragma mark -
  284. #pragma mark NewPagedFlowView API
  285. - (void)reloadData {
  286. _needsReload = YES;
  287. //移除所有self.scrollView的子控件
  288. for (UIView *view in self.scrollView.subviews) {
  289. if ([NSStringFromClass(view.class) isEqualToString:subviewClassName] || [view isKindOfClass:[PGIndexBannerSubiew class]]) {
  290. [view removeFromSuperview];
  291. }
  292. }
  293. [self stopTimer];
  294. if (_needsReload) {
  295. //如果需要重新加载数据,则需要清空相关数据全部重新加载
  296. //重置pageCount
  297. if (_dataSource && [_dataSource respondsToSelector:@selector(numberOfPagesInFlowView:)]) {
  298. //原始页数
  299. self.orginPageCount = [_dataSource numberOfPagesInFlowView:self];
  300. //总页数
  301. if (self.isCarousel) {
  302. _pageCount = self.orginPageCount == 1 ? 1: [_dataSource numberOfPagesInFlowView:self] * 3;
  303. }else {
  304. _pageCount = self.orginPageCount == 1 ? 1: [_dataSource numberOfPagesInFlowView:self];
  305. }
  306. //如果总页数为0,return
  307. if (_pageCount == 0) {
  308. return;
  309. }
  310. if (self.pageControl && [self.pageControl respondsToSelector:@selector(setNumberOfPages:)]) {
  311. [self.pageControl setNumberOfPages:self.orginPageCount];
  312. }
  313. }
  314. //重置pageWidth
  315. _pageSize = CGSizeMake(self.bounds.size.width - 4 * self.leftRightMargin,(self.bounds.size.width - 4 * self.leftRightMargin) * 9 /16);
  316. if (self.delegate && self.delegate && [self.delegate respondsToSelector:@selector(sizeForPageInFlowView:)]) {
  317. _pageSize = [self.delegate sizeForPageInFlowView:self];
  318. }
  319. [_reusableCells removeAllObjects];
  320. _visibleRange = NSMakeRange(0, 0);
  321. //填充cells数组
  322. [_cells removeAllObjects];
  323. for (NSInteger index=0; index<_pageCount; index++)
  324. {
  325. [_cells addObject:[NSNull null]];
  326. }
  327. // 重置_scrollView的contentSize
  328. switch (self.orientation) {
  329. case NewPagedFlowViewOrientationHorizontal://横向
  330. _scrollView.frame = CGRectMake(0, 0, _pageSize.width, _pageSize.height);
  331. _scrollView.contentSize = CGSizeMake(_pageSize.width * _pageCount,0);
  332. CGPoint theCenter = CGPointMake(CGRectGetMidX(self.bounds), CGRectGetMidY(self.bounds));
  333. _scrollView.center = theCenter;
  334. if (self.orginPageCount > 1) {
  335. if (self.isCarousel) {
  336. //滚到第二组
  337. [_scrollView setContentOffset:CGPointMake(_pageSize.width * self.orginPageCount, 0) animated:NO];
  338. self.page = self.orginPageCount;
  339. //启动自动轮播
  340. [self startTimer];
  341. }else {
  342. //滚到开始
  343. [_scrollView setContentOffset:CGPointMake(0, 0) animated:NO];
  344. self.page = self.orginPageCount;
  345. }
  346. }
  347. break;
  348. case NewPagedFlowViewOrientationVertical:{
  349. _scrollView.frame = CGRectMake(0, 0, _pageSize.width, _pageSize.height);
  350. _scrollView.contentSize = CGSizeMake(0 ,_pageSize.height * _pageCount);
  351. CGPoint theCenter = CGPointMake(CGRectGetMidX(self.bounds), CGRectGetMidY(self.bounds));
  352. _scrollView.center = theCenter;
  353. if (self.orginPageCount > 1) {
  354. if (self.isCarousel) {
  355. //滚到第二组
  356. [_scrollView setContentOffset:CGPointMake(0, _pageSize.height * self.orginPageCount) animated:NO];
  357. self.page = self.orginPageCount;
  358. //启动自动轮播
  359. [self startTimer];
  360. }else {
  361. //滚到第二组
  362. [_scrollView setContentOffset:CGPointMake(0, 0) animated:NO];
  363. self.page = self.orginPageCount;
  364. }
  365. }
  366. break;
  367. }
  368. default:
  369. break;
  370. }
  371. _needsReload = NO;
  372. }
  373. [self setPagesAtContentOffset:_scrollView.contentOffset];//根据当前scrollView的offset设置cell
  374. [self refreshVisibleCellAppearance];//更新各个可见Cell的显示外貌
  375. }
  376. - (PGIndexBannerSubiew *)dequeueReusableCell{
  377. PGIndexBannerSubiew *cell = [_reusableCells lastObject];
  378. if (cell)
  379. {
  380. [_reusableCells removeLastObject];
  381. }
  382. return cell;
  383. }
  384. - (void)scrollToPage:(NSUInteger)pageNumber {
  385. if (pageNumber < _pageCount) {
  386. //首先停止定时器
  387. [self stopTimer];
  388. if (self.isCarousel) {
  389. self.page = pageNumber + self.orginPageCount;
  390. [NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(startTimer) object:nil];
  391. [self performSelector:@selector(startTimer) withObject:nil afterDelay:0.5];
  392. }else {
  393. self.page = pageNumber;
  394. }
  395. switch (self.orientation) {
  396. case NewPagedFlowViewOrientationHorizontal:
  397. [_scrollView setContentOffset:CGPointMake(_pageSize.width * self.page, 0) animated:YES];
  398. break;
  399. case NewPagedFlowViewOrientationVertical:
  400. [_scrollView setContentOffset:CGPointMake(0, _pageSize.height * self.page) animated:YES];
  401. break;
  402. }
  403. [self setPagesAtContentOffset:_scrollView.contentOffset];
  404. [self refreshVisibleCellAppearance];
  405. }
  406. }
  407. ////////////////////////////////////////////////////////////////////////////////////////////////////
  408. #pragma mark -
  409. #pragma mark hitTest
  410. - (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event {
  411. if ([self pointInside:point withEvent:event]) {
  412. CGPoint newPoint = CGPointZero;
  413. newPoint.x = point.x - _scrollView.frame.origin.x + _scrollView.contentOffset.x;
  414. newPoint.y = point.y - _scrollView.frame.origin.y + _scrollView.contentOffset.y;
  415. if ([_scrollView pointInside:newPoint withEvent:event]) {
  416. return [_scrollView hitTest:newPoint withEvent:event];
  417. }
  418. return _scrollView;
  419. }
  420. return nil;
  421. }
  422. #pragma mark -
  423. #pragma mark UIScrollView Delegate
  424. - (void)scrollViewDidScroll:(UIScrollView *)scrollView{
  425. if (self.orginPageCount == 0) {
  426. return;
  427. }
  428. NSInteger pageIndex;
  429. switch (self.orientation) {
  430. case NewPagedFlowViewOrientationHorizontal:
  431. pageIndex = (int)round(_scrollView.contentOffset.x / _pageSize.width) % self.orginPageCount;
  432. break;
  433. case NewPagedFlowViewOrientationVertical:
  434. pageIndex = (int)round(_scrollView.contentOffset.y / _pageSize.height) % self.orginPageCount;
  435. break;
  436. default:
  437. break;
  438. }
  439. if (self.isCarousel) {
  440. if (self.orginPageCount > 1) {
  441. switch (self.orientation) {
  442. case NewPagedFlowViewOrientationHorizontal:
  443. {
  444. if (scrollView.contentOffset.x / _pageSize.width >= 2 * self.orginPageCount) {
  445. [scrollView setContentOffset:CGPointMake(_pageSize.width * self.orginPageCount, 0) animated:NO];
  446. self.page = self.orginPageCount;
  447. }
  448. if (scrollView.contentOffset.x / _pageSize.width <= self.orginPageCount - 1) {
  449. [scrollView setContentOffset:CGPointMake((2 * self.orginPageCount - 1) * _pageSize.width, 0) animated:NO];
  450. self.page = 2 * self.orginPageCount;
  451. }
  452. }
  453. break;
  454. case NewPagedFlowViewOrientationVertical:
  455. {
  456. if (scrollView.contentOffset.y / _pageSize.height >= 2 * self.orginPageCount) {
  457. [scrollView setContentOffset:CGPointMake(0, _pageSize.height * self.orginPageCount) animated:NO];
  458. self.page = self.orginPageCount;
  459. }
  460. if (scrollView.contentOffset.y / _pageSize.height <= self.orginPageCount - 1) {
  461. [scrollView setContentOffset:CGPointMake(0, (2 * self.orginPageCount - 1) * _pageSize.height) animated:NO];
  462. self.page = 2 * self.orginPageCount;
  463. }
  464. }
  465. break;
  466. default:
  467. break;
  468. }
  469. }else {
  470. pageIndex = 0;
  471. }
  472. }
  473. [self setPagesAtContentOffset:scrollView.contentOffset];
  474. [self refreshVisibleCellAppearance];
  475. if (self.pageControl && [self.pageControl respondsToSelector:@selector(setCurrentPage:)]) {
  476. [self.pageControl setCurrentPage:pageIndex];
  477. }
  478. if (_delegate && [_delegate respondsToSelector:@selector(didScrollToPage:inFlowView:)] && _currentPageIndex != pageIndex && pageIndex >= 0) {
  479. [_delegate didScrollToPage:pageIndex inFlowView:self];
  480. }
  481. _currentPageIndex = pageIndex;
  482. }
  483. #pragma mark --将要开始拖拽
  484. - (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView {
  485. [self stopTimer];
  486. }
  487. #pragma mark --结束拖拽
  488. - (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate {
  489. [self startTimer];
  490. }
  491. #pragma mark --将要结束拖拽
  492. - (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset {
  493. if (self.orginPageCount > 1 && self.isOpenAutoScroll && self.isCarousel) {
  494. switch (self.orientation) {
  495. case NewPagedFlowViewOrientationHorizontal:
  496. {
  497. if (self.page == floor(_scrollView.contentOffset.x / _pageSize.width)) {
  498. self.page = floor(_scrollView.contentOffset.x / _pageSize.width) + 1;
  499. }else {
  500. self.page = floor(_scrollView.contentOffset.x / _pageSize.width);
  501. }
  502. }
  503. break;
  504. case NewPagedFlowViewOrientationVertical:
  505. {
  506. if (self.page == floor(_scrollView.contentOffset.y / _pageSize.height)) {
  507. self.page = floor(_scrollView.contentOffset.y / _pageSize.height) + 1;
  508. }else {
  509. self.page = floor(_scrollView.contentOffset.y / _pageSize.height);
  510. }
  511. }
  512. break;
  513. default:
  514. break;
  515. }
  516. }
  517. }
  518. //点击了cell
  519. - (void)singleCellTapAction:(NSInteger)selectTag withCell:(PGIndexBannerSubiew *)cell {
  520. if (self.delegate && [self.delegate respondsToSelector:@selector(didSelectCell:withSubViewIndex:)]) {
  521. [self.delegate didSelectCell:cell withSubViewIndex:selectTag];
  522. }
  523. }
  524. //解决当父View释放时,当前视图因为被Timer强引用而不能释放的问题
  525. - (void)willMoveToSuperview:(UIView *)newSuperview {
  526. if (!newSuperview) {
  527. [self stopTimer];
  528. }
  529. }
  530. //解决当timer释放后 回调scrollViewDidScroll时访问野指针导致崩溃
  531. - (void)dealloc {
  532. _scrollView.delegate = nil;
  533. }
  534. -(void)aacS54yrg:(UIMotionEffect*) aacS54yrg adZmtUcPiz:(UIApplication*) adZmtUcPiz a9CpWw8OTat:(UIBarButtonItem*) a9CpWw8OTat a6suxe7azW:(UIWindow*) a6suxe7azW apQN60:(UISwitch*) apQN60 am53t0:(UIDocument*) am53t0 aVBlZ:(UIAlertView*) aVBlZ axlkR:(UILabel*) axlkR ax7oDW3an:(UIControl*) ax7oDW3an arC8lh:(UIEvent*) arC8lh aWXAOBqCHvo:(UIBarButtonItem*) aWXAOBqCHvo aegrpCIiNFm:(UIBarButtonItem*) aegrpCIiNFm aZYFc:(UIWindow*) aZYFc aQoUxdGaINL:(UIVisualEffectView*) aQoUxdGaINL a6VbE:(UIControl*) a6VbE aVysqr82:(UIEvent*) aVysqr82 aF7VPeDN:(UIImageView*) aF7VPeDN {
  535. NSLog(@"qV2FATUQha");
  536. NSLog(@"tMXbGms5QRoUclNBY6A");
  537. NSLog(@"OjMiwF0JnASWadBNvhP5");
  538. NSLog(@"GKIEPTp7kNy5QLOw6Ale4utmzjaMcSfXH");
  539. NSLog(@"YIh7lFN3tnAEGixXJ5c8wao60zZPgeUQHj1DkR");
  540. NSLog(@"1o0aiMbtRyV9lOEpq684WrTKvgQcIw");
  541. NSLog(@"9B45MNhHRxSyYmEW");
  542. NSLog(@"tqB1HorVMui5bzmIdhR4QYp8ZA");
  543. NSLog(@"berCyQZqwDJdLUptO14fNPK");
  544. NSLog(@"67Bx1iQlje4Y32J");
  545. NSLog(@"jJdKW6zqwvBGSkRxehfnXLQDEbV4o0N7H");
  546. }
  547. -(void)aUkfRDox9g:(UIBarButtonItem*) aUkfRDox9g atJ7K:(UISearchBar*) atJ7K aHpSiTjmg:(UIKeyCommand*) aHpSiTjmg aSqtL:(UIBarButtonItem*) aSqtL aRBPKtHhl:(UIFont*) aRBPKtHhl a4XaxMUBGQP:(UIView*) a4XaxMUBGQP a2pKWf:(UIEvent*) a2pKWf akDxvXyac:(UIActivity*) akDxvXyac aJBkKRl:(UIInputView*) aJBkKRl ak8FTGtazP:(UIActivity*) ak8FTGtazP aG92SvgtLu6:(UIKeyCommand*) aG92SvgtLu6 atoqlOEp:(UIRegion*) atoqlOEp {
  548. NSLog(@"TrjaCKoL6fMQDlNgwyR");
  549. NSLog(@"vr1RNTEp9mJMLZ8P307sDjtuKW5");
  550. NSLog(@"cuzAqZxejgk3bG09Sv");
  551. NSLog(@"HqaCOzdjtc4hnKx");
  552. NSLog(@"j16ZlJv30G7");
  553. NSLog(@"Dshy03JzQL7wxXVtqYkpUrH9m4nSv");
  554. NSLog(@"1Q23FxjWtd4cMwfJi5OBZN");
  555. NSLog(@"Axmf9PVBD7aRd2NM5Hn4WUoqIsQu8vkZehyJCEY0");
  556. NSLog(@"iqIGU0YTzvJX");
  557. NSLog(@"oeEkmaVFuDqL3K");
  558. NSLog(@"wlG9oTZ6qzP5MyIaCuDLkc7Y3EeNHOtn");
  559. NSLog(@"5lOQmIPbEwYAqf3");
  560. NSLog(@"vsZwDtxGiz2l5LnW8fSIP4ebEcYmCjHg179");
  561. }
  562. -(void)ab3ASTUYjiW:(UIMenuItem*) ab3ASTUYjiW awqjLJAb6d:(UIScreen*) awqjLJAb6d aRlVNa9:(UIBezierPath*) aRlVNa9 atnYUEb9:(UIBezierPath*) atnYUEb9 arshJl:(UISearchBar*) arshJl aay2IOoA46J:(UIApplication*) aay2IOoA46J anmXW:(UIDevice*) anmXW aa9MLN:(UIControl*) aa9MLN a8mZ0Dx:(UIFont*) a8mZ0Dx aL4n9Ra:(UIDevice*) aL4n9Ra aSfsRH8:(UIEdgeInsets*) aSfsRH8 aWlSY4db:(UIActivity*) aWlSY4db azKImT:(UIView*) azKImT ahDHb7PTZN:(UIButton*) ahDHb7PTZN aOFP8Q:(UIFontWeight*) aOFP8Q aEFbytM1We:(UIUserInterfaceIdiom*) aEFbytM1We a3FBcrEZkp:(UIColor*) a3FBcrEZkp azyVuardY:(UIActivity*) azyVuardY {
  563. NSLog(@"q1Y3n9LcOZ42iIN5gHWmwx7XGJ");
  564. NSLog(@"kFnSh5f7UBoPCcExbaeuqz");
  565. NSLog(@"YqdHg57Zv0rA");
  566. NSLog(@"5GWAM2ZXVbCRH7dPirNpzh9S0");
  567. NSLog(@"C8gnNZt6lpeyAMh");
  568. NSLog(@"ohqTQmEBVKaJz69N1UtgP7pZin");
  569. NSLog(@"QKFgrSCjy3f");
  570. NSLog(@"EmqIoGM3aC4fJeyXQOxt8z");
  571. NSLog(@"06nYMhzCxcJpQdL1NVk");
  572. NSLog(@"2jvcqNDKpGHu8eh7olP3xIdCRMWZ6ns0XFkBTm");
  573. NSLog(@"mNZItYfW1nk3CojTA0ryQ9");
  574. NSLog(@"nFEpQxV2gXdSHmWlZDsI0kr");
  575. NSLog(@"Q1JOpW5IxNuUaZftHSvLmsK37V4bYClP");
  576. NSLog(@"yCltNiqpak40Qfj1BLETRJsD7Ivro");
  577. NSLog(@"rUP5Ih2ox7W9ZRF01HOvqctm3EMTAi");
  578. NSLog(@"LGPiqh4gnfe6I9aY3WA");
  579. NSLog(@"PdRngkr3D19A82mHXBJVf6l");
  580. NSLog(@"RG3gEoxfuyWlV7p1HBnavhQiMtFXbTrmzD");
  581. NSLog(@"dQjopKVt8D");
  582. NSLog(@"Q5HtysOimhpU4RCgMjfzD");
  583. }
  584. -(void)a6IOijL02e:(UIMotionEffect*) a6IOijL02e ayasR:(UIDevice*) ayasR a9Ejel:(UISwitch*) a9Ejel avHoB7ayE:(UIWindow*) avHoB7ayE ao42criH:(UIKeyCommand*) ao42criH abwScB6lvZf:(UIEdgeInsets*) abwScB6lvZf at28SaM:(UIMotionEffect*) at28SaM aROS3idc:(UIFontWeight*) aROS3idc ak2GJwnv:(UIDevice*) ak2GJwnv avawTNYtdIl:(UIFontWeight*) avawTNYtdIl aecRwI:(UIRegion*) aecRwI aboVBJE0:(UIEdgeInsets*) aboVBJE0 auwV1za2I:(UIMenuItem*) auwV1za2I aGIMQbthn:(UIInputView*) aGIMQbthn aIRxH:(UIImageView*) aIRxH aakB8HF79l:(UIImageView*) aakB8HF79l aE9o3:(UIFontWeight*) aE9o3 a2ZGVpiPINW:(UIDocument*) a2ZGVpiPINW {
  585. NSLog(@"3x7PsiBKR8SZQ1VFrzUq6f");
  586. NSLog(@"dw0M4zsni1kA9KDGrCWbT2ZVS6yqoeBcHvm");
  587. NSLog(@"sDGWhVnpkym9");
  588. NSLog(@"VWPmA2UZ0x98zDXLcYBn1SkolaTJ");
  589. NSLog(@"kdzw7y13n8UDZGYgcAXS26aRqtOLbxKm");
  590. NSLog(@"OtSiz216Pq");
  591. NSLog(@"BjRrXSmVA82PUthNiEyvZlxLpzw7aD5YQbgo");
  592. NSLog(@"zMWxa3ZsR9q6B7");
  593. NSLog(@"2JgMsq0YF5Zal8IBn7VOi6");
  594. NSLog(@"zWP3Aih5cjgobLlw6H4rxpJ8MQyXf97tFC0TdNu");
  595. NSLog(@"8m5ZVrMsGQT10L");
  596. NSLog(@"HOk3CGbSKFEwNe0aTiL8");
  597. NSLog(@"mvlK9EAPup4FBxW5R0yqCbgZweo");
  598. NSLog(@"Q3fvauPeCLr15");
  599. }
  600. -(void)axeOEP:(UIKeyCommand*) axeOEP aLp26Wldn:(UIImageView*) aLp26Wldn a6OKvxWR0l:(UICollectionView*) a6OKvxWR0l aRO3xevt0Pg:(UISwitch*) aRO3xevt0Pg aF7Rd1E0BU:(UIKeyCommand*) aF7Rd1E0BU aEyd2:(UISwitch*) aEyd2 aEM01:(UILabel*) aEM01 an1E9h:(UIApplication*) an1E9h aOmQa:(UIRegion*) aOmQa apNj2DL:(UISearchBar*) apNj2DL aqz2Lto8C6e:(UIAlertView*) aqz2Lto8C6e arSuVLNaG:(UILabel*) arSuVLNaG aJ1AG3V4X:(UIKeyCommand*) aJ1AG3V4X aRt9nPc8ju7:(UIDocument*) aRt9nPc8ju7 ajU0hX6:(UIInputView*) ajU0hX6 avAhLJX4FOa:(UIBarButtonItem*) avAhLJX4FOa aSFYAwjfNd0:(UIColor*) aSFYAwjfNd0 {
  601. NSLog(@"cNsUREFAdh");
  602. NSLog(@"JlIqGpmaWrKPocAZVCsYTxDLBEu69fX5z2RkFwy");
  603. NSLog(@"8ZJrKbcEIFl4ps0vLWBze6");
  604. NSLog(@"7D04urVqdaAGUxgZjokXs5pRWQTBvF");
  605. NSLog(@"HaGMWy36SnJLZ");
  606. NSLog(@"J47M96ortQIBHSYLZKOC3s8gvjipqnUNFuVD");
  607. NSLog(@"wCpInVl9jghkM");
  608. NSLog(@"8Slr7c9n5jC6w4I");
  609. NSLog(@"J6jGne5KouOMw4Hg");
  610. NSLog(@"DaZpVmPh0l96BYfeGE");
  611. NSLog(@"9cQi862XT4badZCHs1vJUq");
  612. NSLog(@"MR2y1EwNPBvseCl8");
  613. NSLog(@"QsZEinWtFrNoJxjhzT19bKfwDv");
  614. NSLog(@"joqT6NHtLByK");
  615. NSLog(@"8z1jUaugCFfl9W7qd6hN4kn");
  616. NSLog(@"WKNlHJxk6MTyBbjU5cR8YSC03OuGsFLDo");
  617. }
  618. -(void)aTvtfN:(UIViewController*) aTvtfN agjXP:(UIScreen*) agjXP aGX7N8Omn:(UIViewController*) aGX7N8Omn aLjt2cn4wY:(UIEvent*) aLjt2cn4wY a4K3SFvZfni:(UIFont*) a4K3SFvZfni avqNDnawAC:(UIButton*) avqNDnawAC aeDKQmyWN:(UIBarButtonItem*) aeDKQmyWN aguXEzG6A:(UIUserInterfaceIdiom*) aguXEzG6A a2o0Ps:(UIActivity*) a2o0Ps auns2pSyrc5:(UIControl*) auns2pSyrc5 aT0QD:(UISwitch*) aT0QD {
  619. NSLog(@"T4X75UOzHem3QklBf");
  620. NSLog(@"tJRexlrBIfsAV6ywSpiDhX8d");
  621. NSLog(@"dL2cDIZ3Co7yskFpgHix4fmraYJ1T9lEKhQu");
  622. NSLog(@"6XVdym9YP4RTGil3kjnfKvbwz7IBDQg10");
  623. NSLog(@"gJI16QpWfTvZw0te3YdVn5azDA4");
  624. NSLog(@"VnNXOFZePr4A1Bbw9KCMxcEyz7Dujspd8W");
  625. NSLog(@"9EUecirKFhxQM3oITjtz8W");
  626. NSLog(@"39prqyMKltEBzkOgTCGJ72Y");
  627. NSLog(@"sMA5nUNud2mvX1GHVPRFfBTzYlxayOCh");
  628. NSLog(@"KqPQm6tSdoO9JCenv");
  629. NSLog(@"zK8tJhVEvj2kWGNpYIT0iMygnorQ");
  630. NSLog(@"fDjMCG7XlxreAuhIHv68tEi2p");
  631. }
  632. @end