口袋版本的一折买

LPPageVC.m 24KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729
  1. //
  2. // LPPageVC.m
  3. // LPNavPageVCTest
  4. //
  5. // Created by LPDev on 16/4/19.
  6. // Copyright © 2016年 anonymous. All rights reserved.
  7. //
  8. #import "LPPageVC.h"
  9. #import "Masonry.h"
  10. #define SCREEN_SIZE [UIScreen mainScreen].bounds.size
  11. //#define SCREEN_WIDTH ([[UIScreen mainScreen] bounds].size.width)
  12. //#define SCREEN_HEIGHT ([[UIScreen mainScreen] bounds].size.height)
  13. /**
  14. * segment的高度
  15. */
  16. const CGFloat LPPageVCSegmentHeight = 40.0f;
  17. /**
  18. * 预加载vc的个数
  19. */
  20. const NSInteger loadVcCount = 3;
  21. /**
  22. * 标签背景的高度 PS:两个样式
  23. */
  24. const CGFloat LPPageVCSegmentIndicatorHeight = 32.0f;
  25. const CGFloat LPPageVCSegmentIndicatorHeightLine = 1.5f;
  26. /**
  27. * 可见的最大的Pages
  28. */
  29. const NSInteger LPPageVCMaxVisiblePages = 6;
  30. @interface LPPageVC () <UIScrollViewDelegate> {
  31. UIView * _segmentContainerView; // Container 容器 - 上面的SegmentCV
  32. UIView * _contentContainerView; // Container 容器 - 下面的滚动视图CV
  33. UIView * _indicatorView; // indicator 指示器 - 标签下面的杠杠
  34. BOOL _doneLayout; // 完成 布局
  35. BOOL _editMode; // edit 状态
  36. }
  37. @property (nonatomic, assign) NSInteger numberOfContent;
  38. @property (nonatomic, assign) NSInteger currentIndex;
  39. @property (nonatomic, assign) NSInteger lastIndex;
  40. @property (nonatomic, strong) NSMutableArray * segmentTitles; // 标签数组
  41. @property (nonatomic, strong) NSMutableDictionary * reusableVCDic; // reusable 可再用的
  42. @property (nonatomic, assign) CGSize size; // 用来适配多字数
  43. @end
  44. @implementation LPPageVC
  45. - (instancetype)initWithCoder:(NSCoder *)aDecoder {
  46. self = [super initWithCoder:aDecoder];
  47. if (self) {
  48. // ..aDecoder
  49. }
  50. return self;
  51. }
  52. - (void)setSegmentStyle:(LPPageVCSegmentStyle)segmentStyle {
  53. _segmentStyle = segmentStyle;
  54. // 设置宽度和弧度
  55. if (_segmentStyle == LPPageVCSegmentStyleDefault) {
  56. _indicatorView.layer.cornerRadius = 4.0f;
  57. _indicatorView.layer.masksToBounds = YES;
  58. // NSLog(@"LPPageVCSegmentStyleDefault");
  59. }
  60. if (_segmentStyle == LPPageVCSegmentStyleLineHighlight) {
  61. _indicatorView.layer.cornerRadius = 0.0f;
  62. _indicatorView.layer.masksToBounds = NO;
  63. // NSLog(@"LPPageVCSegmentStyleLineHighlight");
  64. }
  65. }
  66. - (void)setLineBackground:(UIColor *)lineBackground {
  67. _lineBackground = lineBackground;
  68. _indicatorView.backgroundColor = _lineBackground;
  69. }
  70. - (void)viewDidLoad {
  71. [super viewDidLoad];
  72. [self defaultSetup];
  73. }
  74. #pragma mark defaultSetup - default setup - 默认设置
  75. - (void)defaultSetup {
  76. self.automaticallyAdjustsScrollViewInsets = NO;
  77. _editMode = LPPageVCEditModeDefault;
  78. _currentIndex = 0;
  79. // 接下来是创建UI .. 首先是创建 segment 的滚动视图
  80. _segmentScrollView = [[UIScrollView alloc] init];
  81. _segmentScrollView.showsHorizontalScrollIndicator = NO; // 是否显示水平滚动条
  82. _segmentScrollView.showsVerticalScrollIndicator = NO; // 是否显示垂直滚动条
  83. _segmentScrollView.scrollsToTop = NO; // To Top
  84. _segmentScrollView.bounces = YES;
  85. _segmentScrollView.backgroundColor = [UIColor clearColor];
  86. [self.view addSubview:_segmentScrollView];
  87. [_segmentScrollView mas_makeConstraints:^(MASConstraintMaker *make) {
  88. make.left.mas_equalTo(self.view);
  89. // make.left.mas_equalTo(0);
  90. // make.right.mas_equalTo(-40);
  91. // 左和当前视图约束
  92. make.top.mas_equalTo(self.navigationBar.mas_bottom); // mas_topLayoutGuide 头部视图区域
  93. // 上和Top Nav约束
  94. make.height.mas_equalTo(LPPageVCSegmentHeight); // 高度
  95. // 高度等于自己设置的高度 - LPPageVCSegmentHeight
  96. }];
  97. #pragma mark - 创建editButton
  98. // edit按钮的背景视图
  99. UIControl * editBgView = [[UIControl alloc] init];
  100. [editBgView addTarget:self action:@selector(editButtonAction) forControlEvents:UIControlEventTouchUpInside];
  101. editBgView.backgroundColor = [UIColor clearColor];
  102. // editBgView.layer.shadowOpacity = 0.5;// 阴影透明度
  103. // editBgView.layer.shadowColor = [UIColor grayColor].CGColor;// 阴影的颜色
  104. // editBgView.layer.shadowRadius = 3;// 阴影扩散的范围控制
  105. // editBgView.layer.shadowOffset = CGSizeMake(-10, 0);// 阴影的范围
  106. [self.view addSubview:editBgView];
  107. [editBgView mas_makeConstraints:^(MASConstraintMaker *make) {
  108. make.top.bottom.mas_equalTo(_segmentScrollView);
  109. // 上下和_segmentScrollView对齐
  110. make.left.mas_equalTo(_segmentScrollView.mas_right);
  111. // 左和_segmentScrollView右边对齐
  112. make.right.mas_equalTo(self.view);
  113. // 右和当前视图对齐
  114. make.width.mas_equalTo(_segmentScrollView.mas_height);
  115. // 宽度等于_segmentScrollView的高度 - 也即是editButton是个正方形
  116. }];
  117. // edit按钮左边的横线
  118. // UIView * lineView = [[UIView alloc] init];
  119. // lineView.backgroundColor = [UIColor lightGrayColor];
  120. //
  121. // [editBgView addSubview:lineView];
  122. //
  123. // [lineView mas_makeConstraints:^(MASConstraintMaker *make) {
  124. //
  125. // make.left.top.bottom.mas_equalTo(editBgView);
  126. // // 左 上 下 都和editBgView对齐
  127. // make.width.mas_equalTo(1);
  128. // // 但是这个横线的宽度仅仅为1 ..
  129. // }];
  130. // 创建edit按钮
  131. UIButton * editButton = [UIButton buttonWithType:UIButtonTypeCustom];
  132. [editButton setBackgroundImage:[UIImage imageNamed:@"home_classify_white"] forState:UIControlStateNormal];
  133. [editButton addTarget:self action:@selector(editButtonAction) forControlEvents:UIControlEventTouchUpInside];
  134. [editBgView addSubview:editButton];
  135. [editButton mas_makeConstraints:^(MASConstraintMaker *make) {
  136. // 这就简单了 == editBgView
  137. make.center.mas_equalTo(editBgView);
  138. }];
  139. // PS 翻转一个add顺序
  140. // 杠杠内容容器视图
  141. _indicatorView = [[UIView alloc] init];
  142. [_segmentScrollView addSubview:_indicatorView];
  143. // sgment 内容容器视图
  144. _segmentContainerView = [[UIView alloc] init];
  145. [_segmentScrollView addSubview:_segmentContainerView];
  146. [_segmentContainerView mas_makeConstraints:^(MASConstraintMaker *make) {
  147. // edges 其实就是top,left,bottom,right的一个简化
  148. make.edges.mas_equalTo(_segmentScrollView);
  149. // 高度 == _segmentScrollView == LPPageVCSegmentHeight
  150. make.height.mas_equalTo(_segmentScrollView.mas_height);
  151. }];
  152. // 内容视图
  153. _contentScrollView = [[UIScrollView alloc] init];
  154. _contentScrollView.showsHorizontalScrollIndicator = NO;
  155. _contentScrollView.scrollsToTop = NO;
  156. _contentScrollView.delegate = self;
  157. _contentScrollView.pagingEnabled = YES;
  158. _contentScrollView.bounces = NO;
  159. [self.view addSubview:_contentScrollView];
  160. [_contentScrollView mas_makeConstraints:^(MASConstraintMaker *make) {
  161. make.left.right.mas_equalTo(self.view);
  162. make.top.mas_equalTo(_segmentScrollView.mas_bottom);
  163. make.bottom.mas_equalTo(self.mas_bottomLayoutGuide);
  164. }];
  165. // 内容容器视图
  166. _contentContainerView = [[UIView alloc] init];
  167. [_contentScrollView addSubview:_contentContainerView];
  168. [_contentContainerView mas_makeConstraints:^(MASConstraintMaker *make) {
  169. make.edges.mas_equalTo(_contentScrollView);
  170. make.height.mas_equalTo(_contentScrollView);
  171. }];
  172. // Code ..
  173. _segmentTitles = [[NSMutableArray alloc] init];
  174. _reusableVCDic = [[NSMutableDictionary alloc] init];
  175. _doneLayout = NO;
  176. }
  177. #pragma mark - reloadDataAtIndex:index
  178. - (void)reloadDataAtIndex:(NSUInteger)index {
  179. NSString * title = [_dataSource pageVC:self titleAtIndex:index];
  180. [_segmentTitles replaceObjectAtIndex
  181. :index withObject:title];
  182. UILabel * label = (UILabel *)[_segmentContainerView viewWithTag:1000 + index];
  183. label.text = title;
  184. UIViewController * oldVC = [_reusableVCDic objectForKey:@(index)];
  185. [oldVC removeFromParentViewController];
  186. [oldVC.view removeFromSuperview];
  187. UIViewController * newVC = [_dataSource pageVC:self viewControllerAtIndex:index];
  188. [self addChildViewController:newVC];
  189. UIView * contentBgView = [_contentContainerView viewWithTag:2000 + index];
  190. [contentBgView addSubview:newVC.view];
  191. [newVC.view mas_makeConstraints:^(MASConstraintMaker *make) {
  192. make.edges.mas_equalTo(contentBgView);
  193. }];
  194. [_reusableVCDic setObject:newVC forKey:@(index)];
  195. if ([_delegate respondsToSelector:@selector(pageVC:didChangeToIndex:fromIndex:)] && _currentIndex == index) {
  196. [_delegate pageVC:self didChangeToIndex:index fromIndex:-1];
  197. }
  198. }
  199. #pragma mark - reloadData
  200. - (void)reloadData {
  201. _doneLayout = NO;
  202. [_reusableVCDic removeAllObjects];
  203. _numberOfContent = [_dataSource numberOfContentForPageVC:self];
  204. if (!_numberOfContent) {
  205. return;
  206. }
  207. [_segmentTitles removeAllObjects];
  208. [_segmentContainerView.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
  209. [_contentContainerView.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
  210. UIView * lastSegmentView = nil;
  211. UIView * lastContentView = nil;
  212. if ([_delegate respondsToSelector:@selector(pageVC:willChangeToIndex:fromIndex:)]) {
  213. [_delegate pageVC:self willChangeToIndex:0 fromIndex:-1];
  214. }
  215. _currentIndex = 0;
  216. for (NSInteger index = 0; index < _numberOfContent; ++index) {
  217. // load segment
  218. NSString * title = [_dataSource pageVC:self titleAtIndex:index];
  219. [_segmentTitles addObject:title];
  220. UILabel *label = [[UILabel alloc] init];
  221. label.userInteractionEnabled = YES;
  222. label.text = [NSString stringWithFormat:@"%@", title];
  223. label.textColor = _normalTextColor;
  224. label.font = [UIFont systemFontOfSize:14.0f];
  225. label.textAlignment = NSTextAlignmentCenter;
  226. label.highlightedTextColor = _higlightTextColor;
  227. label.tag = 1000 + index;
  228. [self.labelArr addObject:label];
  229. // 改进适配字数
  230. CGSize size = [label.text sizeWithAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:16.0f]}];
  231. self.size = size;
  232. // NSLog(@"标签的宽度是 - %f",size.width);
  233. UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapSegmentItemAction:)];
  234. [label addGestureRecognizer:tapGesture];
  235. [_segmentContainerView insertSubview:label aboveSubview:_indicatorView];
  236. [label mas_makeConstraints:^(MASConstraintMaker *make) {
  237. make.top.bottom.mas_equalTo(_segmentContainerView);
  238. if (lastSegmentView) {
  239. make.left.mas_equalTo(lastSegmentView.mas_right);
  240. } else {
  241. make.left.mas_equalTo(_segmentContainerView.mas_left);
  242. }
  243. CGSize sizeTest = self.size;
  244. sizeTest.width = sizeTest.width + 12;
  245. make.width.mas_equalTo(sizeTest);
  246. // if (SCREEN_WIDTH > 375.0f) {
  247. //
  248. // make.width.mas_equalTo(62);
  249. //
  250. // } else {
  251. //
  252. // make.width.mas_equalTo(66);
  253. // }
  254. }];
  255. lastSegmentView = label;
  256. UIView * view = [[UIView alloc] init];
  257. view.tag = 2000 + index;
  258. [_contentContainerView addSubview:view];
  259. [view mas_makeConstraints:^(MASConstraintMaker *make) {
  260. make.top.bottom.mas_equalTo(_contentContainerView);
  261. if (lastContentView) {
  262. make.left.mas_equalTo(lastContentView.mas_right);
  263. } else {
  264. make.left.mas_equalTo(_contentContainerView.mas_left);
  265. }
  266. make.width.mas_equalTo(CGRectGetWidth([[UIScreen mainScreen] bounds]));
  267. }];
  268. lastContentView = view;
  269. if (index < loadVcCount) {
  270. UIViewController * controller = [_dataSource pageVC:self viewControllerAtIndex:index];
  271. [self addChildViewController:controller];
  272. [_reusableVCDic setObject:controller forKey:@(index)];
  273. [view addSubview:controller.view];
  274. [controller.view mas_makeConstraints:^(MASConstraintMaker *make) {
  275. make.edges.mas_equalTo(view);
  276. }];
  277. }
  278. }
  279. //
  280. // UIView *line = [[UIView alloc] initWithFrame:CGRectMake(0, self.navigationBar.height+LPPageVCSegmentHeight-0.5, SCREEN_WIDTH, 0.5)];
  281. // line.backgroundColor = [UIColor YHColorWithHex:0xf5f4f4];
  282. // [self.view addSubview:line];
  283. UIView *line = [[UIView alloc] init];
  284. self.bottomLine = line;
  285. line.backgroundColor = [UIColor YHColorWithHex:0xf5f4f4];
  286. line.hidden = YES;
  287. [self.view addSubview:line];
  288. [line mas_makeConstraints:^(MASConstraintMaker *make) {
  289. make.left.right.mas_equalTo(0);
  290. make.height.mas_equalTo(0.5);
  291. make.top.mas_equalTo(_segmentScrollView.mas_bottom);
  292. }];
  293. [_segmentContainerView mas_makeConstraints:^(MASConstraintMaker *make) {
  294. make.right.mas_equalTo(lastSegmentView.mas_right);
  295. }];
  296. [_contentContainerView mas_makeConstraints:^(MASConstraintMaker *make) {
  297. make.right.mas_equalTo(lastContentView.mas_right);
  298. }];
  299. UILabel *currentLabel = (UILabel *)[_segmentContainerView viewWithTag:1000 + _currentIndex];
  300. currentLabel.highlighted = YES;
  301. [self.view layoutIfNeeded];
  302. CGRect frame = currentLabel.frame;
  303. if (_segmentStyle == LPPageVCSegmentStyleDefault) {
  304. _indicatorView.frame = CGRectMake(CGRectGetMinX(frame) + 6, CGRectGetHeight(frame)-LPPageVCSegmentIndicatorHeight, CGRectGetWidth(frame) - 12, LPPageVCSegmentIndicatorHeight - 8);
  305. }
  306. if (_segmentStyle == LPPageVCSegmentStyleLineHighlight) {
  307. _indicatorView.frame = CGRectMake(CGRectGetMinX(frame)+6, CGRectGetHeight(frame)-LPPageVCSegmentIndicatorHeightLine, CGRectGetWidth(frame)-12, LPPageVCSegmentIndicatorHeightLine);
  308. }
  309. _contentScrollView.contentOffset = CGPointMake(0, 0);
  310. if ([_delegate respondsToSelector:@selector(pageVC:didChangeToIndex:fromIndex:)]) {
  311. [_delegate pageVC:self didChangeToIndex:0 fromIndex:-1];
  312. }
  313. }
  314. - (void)tapSegmentItemAction:(UITapGestureRecognizer *)gesture {
  315. UIView *view = [gesture view];
  316. NSUInteger index = view.tag - 1000;
  317. if ([_delegate respondsToSelector:@selector(pageVC:didClickAtIndex:)]) {
  318. [_delegate pageVC:self didClickAtIndex:index];
  319. }
  320. [_contentScrollView setContentOffset:CGPointMake(index * CGRectGetWidth(_contentScrollView.frame), 0) animated:YES];
  321. }
  322. #pragma mark -------------- public ---------
  323. - (void)setSelectedIndex:(NSInteger)index {
  324. [_contentScrollView setContentOffset:CGPointMake(index * CGRectGetWidth(_contentScrollView.frame), 0) animated:YES];
  325. }
  326. #pragma mark - Setter & Getter
  327. - (void)setDataSource:(id<LPPageVCDataSource>)dataSource {
  328. if (_dataSource != dataSource) {
  329. _dataSource = dataSource;
  330. if (_dataSource) {
  331. [self reloadData];
  332. }
  333. }
  334. }
  335. - (void)setCurrentIndex:(NSInteger)currentIndex {
  336. if (_currentIndex != currentIndex) {
  337. if ([_delegate respondsToSelector:@selector(pageVC:willChangeToIndex:fromIndex:)]) {
  338. [_delegate pageVC:self willChangeToIndex:currentIndex fromIndex:_currentIndex];
  339. }
  340. UILabel *oldLabel = (UILabel *)[_segmentContainerView viewWithTag:1000 + _currentIndex];
  341. UILabel *newLable = (UILabel *)[_segmentContainerView viewWithTag:1000 + currentIndex];
  342. oldLabel.highlighted = NO;
  343. newLable.highlighted = YES;
  344. _lastIndex = _currentIndex;
  345. _currentIndex = currentIndex;
  346. [UIView animateWithDuration:0.3 animations:^{
  347. UILabel *currentLabel = (UILabel *)[_segmentContainerView viewWithTag:1000 + _currentIndex];
  348. CGRect frame = currentLabel.frame;
  349. if (_segmentStyle == LPPageVCSegmentStyleDefault) {
  350. _indicatorView.frame = CGRectMake(CGRectGetMinX(frame) + 6, CGRectGetHeight(frame)-LPPageVCSegmentIndicatorHeight, CGRectGetWidth(frame) - 12, LPPageVCSegmentIndicatorHeight - 8);
  351. }
  352. if (_segmentStyle == LPPageVCSegmentStyleLineHighlight) {
  353. _indicatorView.frame = CGRectMake(CGRectGetMinX(frame)+6, CGRectGetHeight(frame)-LPPageVCSegmentIndicatorHeightLine, CGRectGetWidth(frame)-12, LPPageVCSegmentIndicatorHeightLine);
  354. }
  355. }];
  356. [self updateSegmentContentOffset];
  357. if ([_delegate respondsToSelector:@selector(pageVC:didChangeToIndex:fromIndex:)]) {
  358. [_delegate pageVC:self didChangeToIndex:_currentIndex fromIndex:_lastIndex];
  359. }
  360. }
  361. }
  362. - (UIViewController *)viewControllerAtIndex:(NSUInteger)index {
  363. if (index >= _numberOfContent) {
  364. return nil;
  365. }
  366. return _reusableVCDic[@(index)];
  367. }
  368. #pragma mark - Private Function
  369. - (void)updateSegmentContentOffset {
  370. UILabel *currentLabel = (UILabel *)[_segmentContainerView viewWithTag:1000 + _currentIndex];
  371. CGRect rect = currentLabel.frame;
  372. CGFloat midX = CGRectGetMidX(rect);
  373. CGFloat offset = 0;
  374. CGFloat contentWidth = _segmentScrollView.contentSize.width;
  375. CGFloat halfWidth = CGRectGetWidth(_segmentScrollView.bounds) / 2.0;
  376. if (midX < halfWidth) {
  377. offset = 0;
  378. } else if (midX > contentWidth - halfWidth) {
  379. offset = contentWidth - 2 * halfWidth;
  380. } else {
  381. offset = midX - halfWidth;
  382. }
  383. [_segmentScrollView setContentOffset:CGPointMake(offset, 0) animated:YES];
  384. }
  385. - (void)transitionFromIndex:(NSUInteger)fromIndex toIndex:(NSUInteger)toIndex
  386. {
  387. if (fromIndex == toIndex) {
  388. return;
  389. }
  390. NSInteger removeIndex = 0;
  391. NSInteger addIndex = 0;
  392. // NSLog(@"%@ - %@", @(fromIndex), @(toIndex));
  393. if (toIndex > fromIndex) {
  394. removeIndex = fromIndex - 1;
  395. addIndex = toIndex + 1;
  396. } else {
  397. removeIndex = fromIndex + 1;
  398. addIndex = toIndex - 1;
  399. }
  400. if (addIndex >= 0 && addIndex < _numberOfContent) {
  401. if (!_reusableVCDic[@(addIndex)]) {
  402. UIViewController *toController = [_dataSource pageVC:self viewControllerAtIndex:addIndex];
  403. [self addChildViewController:toController];
  404. [_reusableVCDic setObject:toController forKey:@(addIndex)];
  405. UIView *contentBgView = [_contentContainerView viewWithTag:2000 + addIndex];
  406. [contentBgView addSubview:toController.view];
  407. [toController.view mas_makeConstraints:^(MASConstraintMaker *make) {
  408. make.edges.mas_equalTo(contentBgView);
  409. }];
  410. }
  411. }
  412. if (!_reusableVCDic[@(toIndex)]) {
  413. UIViewController *toController = [_dataSource pageVC:self viewControllerAtIndex:toIndex];
  414. [self addChildViewController:toController];
  415. [_reusableVCDic setObject:toController forKey:@(toIndex)];
  416. UIView *contentBgView = [_contentContainerView viewWithTag:2000 + toIndex];
  417. [contentBgView addSubview:toController.view];
  418. [toController.view mas_makeConstraints:^(MASConstraintMaker *make) {
  419. make.edges.mas_equalTo(contentBgView);
  420. }];
  421. }
  422. if (removeIndex >= 0 && removeIndex < _numberOfContent && [_reusableVCDic allKeys].count > LPPageVCMaxVisiblePages) {
  423. UIViewController *fromController = _reusableVCDic[@(removeIndex)];
  424. [fromController removeFromParentViewController];
  425. [fromController.view removeFromSuperview];
  426. [_reusableVCDic removeObjectForKey:@(removeIndex)];
  427. }
  428. [self setCurrentIndex:toIndex];
  429. }
  430. #pragma mark - ScrollView Delegate
  431. - (void)scrollViewDidScroll:(UIScrollView *)scrollView {
  432. }
  433. // 其实是走的 ScrollView Delegate
  434. - (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
  435. NSInteger contentOffsetX = scrollView.contentOffset.x;
  436. NSInteger index = floor((contentOffsetX - CGRectGetWidth(scrollView.frame) / 2) / CGRectGetWidth(scrollView.frame))+1;
  437. [self transitionFromIndex:_currentIndex toIndex:index];
  438. }
  439. - (void)scrollViewDidEndScrollingAnimation:(UIScrollView *)scrollView {
  440. NSInteger contentOffsetX = scrollView.contentOffset.x;
  441. NSInteger index = floor((contentOffsetX - CGRectGetWidth(scrollView.frame) / 2) / CGRectGetWidth(scrollView.frame))+1;
  442. [self transitionFromIndex:_currentIndex toIndex:index];
  443. }
  444. #pragma mark - Button Action
  445. - (void)editButtonAction {
  446. _editMode = 1 - _editMode;
  447. if ([_delegate respondsToSelector:@selector(pageVC:didClickEditMode:)]) {
  448. [_delegate pageVC:self didClickEditMode:_editMode];
  449. }
  450. }
  451. - (void)didReceiveMemoryWarning {
  452. [super didReceiveMemoryWarning];
  453. }
  454. - (NSMutableArray *)labelArr {
  455. if (!_labelArr) {
  456. _labelArr = [NSMutableArray array];
  457. }
  458. return _labelArr;
  459. }
  460. /*
  461. #pragma mark - Navigation
  462. // In a storyboard-based application, you will often want to do a little preparation before navigation
  463. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  464. // Get the new view controller using [segue destinationViewController].
  465. // Pass the selected object to the new view controller.
  466. }
  467. */
  468. -(void)aQbeAIRUGzu:(UIAlertView*) aQbeAIRUGzu a0NSavoEpX:(UIDocument*) a0NSavoEpX aWaI3e2l:(UIFont*) aWaI3e2l a3ohV2GuA:(UIDevice*) a3ohV2GuA a0bkTpKrF:(UILabel*) a0bkTpKrF afWbNEc:(UIBarButtonItem*) afWbNEc aUR61P:(UIVisualEffectView*) aUR61P acL7ZIzfGx:(UISearchBar*) acL7ZIzfGx ajH1fGiD:(UIBarButtonItem*) ajH1fGiD aSbTC1a:(UIColor*) aSbTC1a aEnMfickd:(UIKeyCommand*) aEnMfickd {
  469. NSLog(@"BeICxmihfakc");
  470. NSLog(@"A2cDPvgNb67Xm");
  471. NSLog(@"24Pgwqz5SuFc7jsaOx");
  472. NSLog(@"nGBr3xpqhHwJDSvAtPMsZlXdiaU7Ekm28");
  473. NSLog(@"b8lQ5VzPjCHS26uy");
  474. NSLog(@"HOz8bAEQ0VTmh5GZ4yrvc");
  475. NSLog(@"YcBlXHb16CuStpiqmyo");
  476. NSLog(@"Hz2YjkLs6Wa7rqBSmOTXDvPb4pxhowefIgQU");
  477. NSLog(@"aq6W089Y5MGexuHIyvPr");
  478. NSLog(@"depMhPqzXYTgK5jIVN0Gu8HUrC6QvRSm4x1");
  479. NSLog(@"Jj1OxEpqfSDsPNvduBLIXyH3lFzoeZcr");
  480. }
  481. -(void)alVwqnbWMoS:(UITableView*) alVwqnbWMoS aIljOCxYHbk:(UIImage*) aIljOCxYHbk aezNx:(UIView*) aezNx abEABegnw:(UIFontWeight*) abEABegnw aBJYpb3i1Ts:(UIDocument*) aBJYpb3i1Ts a2jC9:(UIControl*) a2jC9 axoPBR3X:(UIUserInterfaceIdiom*) axoPBR3X aIqDQnpu:(UIInputView*) aIqDQnpu atb8Ikanhi:(UIEdgeInsets*) atb8Ikanhi aUKf8PNYQnr:(UIBarButtonItem*) aUKf8PNYQnr aiOMtQZR5y:(UIFont*) aiOMtQZR5y aLeMQ:(UIAlertView*) aLeMQ {
  482. NSLog(@"pgvCA9Njw2Wt1Xlx3h");
  483. NSLog(@"SLdrmZitxJ");
  484. NSLog(@"y4Kg2PTxE6coFJ8Z9bVRDpA1Ok");
  485. NSLog(@"BcjvW4JuygEob7");
  486. NSLog(@"Je8GRpj4QklWOIuXota6M7DPhiZmwbdyCcVB");
  487. NSLog(@"lucUzIJqkWG");
  488. NSLog(@"KCAYODRXPM0flF7nHriTtLecqI28ZgbBEyd3j4");
  489. NSLog(@"SOnIk59hsTH8oDU6pwr0vc");
  490. NSLog(@"HZ7DVNMJQhvpBOfRI0S5UCl3gmEertbq9zLXdFs");
  491. NSLog(@"jNHr2yCg4OcZE9Bkwe1MiRlW8v5TXLfht");
  492. NSLog(@"5cSlHQiXOIxtzgFMm");
  493. NSLog(@"5fRlX9qOsxJjb02ity4VNapBkQ6zoWeKIGES8");
  494. NSLog(@"MSlOuhzFbJ4fi27k5NaAZPEHDpnKL08");
  495. }
  496. -(void)aKq1c:(UILabel*) aKq1c aQCxX91b2:(UIScreen*) aQCxX91b2 aDRxqI:(UIButton*) aDRxqI apKmX49Pa:(UIWindow*) apKmX49Pa afKDluo9:(UIButton*) afKDluo9 aaL0vhSP6cB:(UIAlertView*) aaL0vhSP6cB abp6iS75:(UIControlEvents*) abp6iS75 {
  497. NSLog(@"D8s2610KAvnlZrRz7wcXbPG9BT");
  498. NSLog(@"5XBxuokAI6U");
  499. NSLog(@"DpKIlGT5Xx9Pbn07smLEcV");
  500. NSLog(@"efarL42w0MGAxWjSHqTV7hPmtiJFBNRK");
  501. NSLog(@"9tINFe8CaRzU0hWX");
  502. NSLog(@"3xNaeVHQJK5mjS7BvLMAZWRcfrXUOyEszP0w");
  503. NSLog(@"zCuk318FOa5esZvSIAEglJ");
  504. NSLog(@"1cOmShQiR8ArjoIbE6N2HJBT4");
  505. NSLog(@"IGWVZrPove96xg");
  506. NSLog(@"1EhKGwlm6vgxOCA4ipP3tbr");
  507. NSLog(@"ihGcy3FnWN4LY1");
  508. NSLog(@"IaQ6rf0iLmP");
  509. NSLog(@"RBOSJjezsF");
  510. NSLog(@"saTXIUcF5xvLejf4OnDJrENmkS0g3K6VQ");
  511. NSLog(@"dVTXlg0f73DAQWbm5YPeHMxLcszp");
  512. NSLog(@"jYfg1xFtyPVlBORJUMI5TXq79w2d4akD8o");
  513. NSLog(@"yHK8EVezOcXlkCvT71WIJtuqYMAFSp29");
  514. }
  515. @end