SCIndexView.m 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560
  1. #import "SCIndexView.h"
  2. #define kSCIndexViewSpace (self.configuration.indexItemHeight + self.configuration.indexItemsSpace)
  3. #define kSCIndexViewMargin ((self.bounds.size.height - kSCIndexViewSpace * self.dataSource.count) / 2)
  4. #define kSCIndexViewInsetTop (self.translucentForTableViewInNavigationBar ? UIApplication.sharedApplication.statusBarFrame.size.height + 44 : 0)
  5. static NSTimeInterval kAnimationDuration = 0.25;
  6. // 根据section值获取TextLayer的中心点y值
  7. static inline CGFloat SCGetTextLayerCenterY(NSUInteger position, CGFloat margin, CGFloat space)
  8. {
  9. return margin + (position + 1.0 / 2) * space;
  10. }
  11. // 根据y值获取TextLayer的section值
  12. static inline NSInteger SCPositionOfTextLayerInY(CGFloat y, CGFloat margin, CGFloat space)
  13. {
  14. CGFloat position = (y - margin) / space - 1.0 / 2;
  15. if (position <= 0) return 0;
  16. NSUInteger bigger = (NSUInteger)ceil(position);
  17. NSUInteger smaller = bigger - 1;
  18. CGFloat biggerCenterY = SCGetTextLayerCenterY(bigger, margin, space);
  19. CGFloat smallerCenterY = SCGetTextLayerCenterY(smaller, margin, space);
  20. return biggerCenterY + smallerCenterY > 2 * y ? smaller : bigger;
  21. }
  22. @interface SCTextLayer : CATextLayer
  23. @property (nonatomic, strong) UIFont *itemFont;
  24. @end
  25. @implementation SCTextLayer
  26. - (void)drawInContext:(CGContextRef)context {
  27. CGFloat height = self.bounds.size.height;
  28. CGFloat fontSize = self.itemFont.lineHeight;
  29. CGFloat yOffset = (height - fontSize) / 2;
  30. CGContextSaveGState(context);
  31. CGContextTranslateCTM(context, 0, yOffset);
  32. [super drawInContext:context];
  33. CGContextRestoreGState(context);
  34. }
  35. - (void)setItemFont:(UIFont *)itemFont {
  36. _itemFont = itemFont;
  37. self.font = (__bridge CFTypeRef _Nullable)(itemFont.fontName);
  38. self.fontSize = itemFont.pointSize;
  39. }
  40. @end
  41. @interface SCIndexView ()
  42. @property (nonatomic, strong, nullable) CAShapeLayer *searchLayer;
  43. @property (nonatomic, strong) NSMutableArray<SCTextLayer *> *subTextLayers;
  44. @property (nonatomic, strong) UILabel *indicator;
  45. @property (nonatomic, weak) UITableView *tableView;
  46. // 触摸索引视图
  47. @property (nonatomic, assign, getter=isTouchingIndexView) BOOL touchingIndexView;
  48. // 触感反馈
  49. @property (nonatomic, strong) UIImpactFeedbackGenerator *generator NS_AVAILABLE_IOS(10_0);
  50. @end
  51. @implementation SCIndexView
  52. #pragma mark - Life Cycle
  53. - (instancetype)initWithTableView:(UITableView *)tableView configuration:(SCIndexViewConfiguration *)configuration
  54. {
  55. if (self = [super initWithFrame:tableView.frame]) {
  56. _tableView = tableView;
  57. _currentSection = NSUIntegerMax;
  58. _configuration = configuration;
  59. _translucentForTableViewInNavigationBar = YES;
  60. [self addSubview:self.indicator];
  61. }
  62. return self;
  63. }
  64. - (void)layoutSubviews {
  65. [super layoutSubviews];
  66. CGFloat space = kSCIndexViewSpace;
  67. CGFloat margin = kSCIndexViewMargin;
  68. [CATransaction begin];
  69. [CATransaction setDisableActions:YES];
  70. if (self.searchLayer && !self.searchLayer.hidden) {
  71. self.searchLayer.frame = CGRectMake(self.bounds.size.width - self.configuration.indexItemRightMargin - self.configuration.indexItemHeight, SCGetTextLayerCenterY(0, margin, space) - self.configuration.indexItemHeight / 2, self.configuration.indexItemHeight, self.configuration.indexItemHeight);
  72. self.searchLayer.cornerRadius = self.configuration.indexItemHeight / 2;
  73. self.searchLayer.contentsScale = UIScreen.mainScreen.scale;
  74. self.searchLayer.backgroundColor = self.configuration.indexItemBackgroundColor.CGColor;
  75. }
  76. NSInteger deta = self.searchLayer ? 1 : 0;
  77. for (int i = 0; i < self.subTextLayers.count; i++) {
  78. SCTextLayer *textLayer = self.subTextLayers[i];
  79. NSUInteger section = i + deta;
  80. textLayer.frame = CGRectMake(self.bounds.size.width - self.configuration.indexItemRightMargin - self.configuration.indexItemHeight, SCGetTextLayerCenterY(section, margin, space) - self.configuration.indexItemHeight / 2, self.configuration.indexItemHeight, self.configuration.indexItemHeight);
  81. }
  82. [CATransaction commit];
  83. }
  84. #pragma mark - Public Methods
  85. - (void)refreshCurrentSection {
  86. [self onActionWithScroll];
  87. }
  88. #pragma mark -
  89. - (void)configSubLayersAndSubviews
  90. {
  91. BOOL hasSearchLayer = [self.dataSource.firstObject isEqualToString:UITableViewIndexSearch];
  92. NSUInteger deta = 0;
  93. if (hasSearchLayer) {
  94. if (!self.searchLayer) {
  95. self.searchLayer = [self createSearchLayer];
  96. [self.layer addSublayer:self.searchLayer];
  97. }
  98. self.searchLayer.hidden = NO;
  99. deta = 1;
  100. } else if (self.searchLayer) {
  101. self.searchLayer.hidden = YES;
  102. }
  103. NSInteger countDifference = self.dataSource.count - deta - self.subTextLayers.count;
  104. if (countDifference > 0) {
  105. for (int i = 0; i < countDifference; i++) {
  106. SCTextLayer *textLayer = [SCTextLayer layer];
  107. [self.layer addSublayer:textLayer];
  108. [self.subTextLayers addObject:textLayer];
  109. }
  110. } else {
  111. for (int i = 0; i < -countDifference; i++) {
  112. SCTextLayer *textLayer = self.subTextLayers.lastObject;
  113. [textLayer removeFromSuperlayer];
  114. [self.subTextLayers removeObject:textLayer];
  115. }
  116. }
  117. CGFloat space = kSCIndexViewSpace;
  118. CGFloat margin = kSCIndexViewMargin;
  119. [CATransaction begin];
  120. [CATransaction setDisableActions:YES];
  121. if (hasSearchLayer) {
  122. self.searchLayer.frame = CGRectMake(self.bounds.size.width - self.configuration.indexItemRightMargin - self.configuration.indexItemHeight, SCGetTextLayerCenterY(0, margin, space) - self.configuration.indexItemHeight / 2, self.configuration.indexItemHeight, self.configuration.indexItemHeight);
  123. self.searchLayer.cornerRadius = self.configuration.indexItemHeight / 2;
  124. self.searchLayer.contentsScale = UIScreen.mainScreen.scale;
  125. self.searchLayer.backgroundColor = self.configuration.indexItemBackgroundColor.CGColor;
  126. }
  127. for (int i = 0; i < self.subTextLayers.count; i++) {
  128. SCTextLayer *textLayer = self.subTextLayers[i];
  129. NSUInteger section = i + deta;
  130. textLayer.frame = CGRectMake(self.bounds.size.width - self.configuration.indexItemRightMargin - self.configuration.indexItemHeight, SCGetTextLayerCenterY(section, margin, space) - self.configuration.indexItemHeight / 2, self.configuration.indexItemHeight, self.configuration.indexItemHeight);
  131. textLayer.string = self.dataSource[section];
  132. textLayer.itemFont = self.configuration.indexItemTextFont;
  133. textLayer.cornerRadius = self.configuration.indexItemHeight / 2;
  134. textLayer.alignmentMode = kCAAlignmentCenter;
  135. textLayer.contentsScale = UIScreen.mainScreen.scale;
  136. textLayer.backgroundColor = self.configuration.indexItemBackgroundColor.CGColor;
  137. textLayer.foregroundColor = self.configuration.indexItemTextColor.CGColor;
  138. }
  139. [CATransaction commit];
  140. if (self.subTextLayers.count == 0) {
  141. self.currentSection = NSUIntegerMax;
  142. } else if (self.currentSection == NSUIntegerMax) {
  143. self.currentSection = self.searchLayer ? SCIndexViewSearchSection : 0;
  144. } else {
  145. self.currentSection = self.subTextLayers.count - 1;
  146. }
  147. }
  148. - (void)configCurrentSection
  149. {
  150. NSInteger currentSection = SCIndexViewInvalidSection;
  151. if (self.delegate && [self.delegate respondsToSelector:@selector(sectionOfIndexView:tableViewDidScroll:)]) {
  152. currentSection = [self.delegate sectionOfIndexView:self tableViewDidScroll:self.tableView];
  153. if ((currentSection >= 0 && currentSection != SCIndexViewInvalidSection)
  154. || currentSection == SCIndexViewSearchSection) {
  155. self.currentSection = currentSection;
  156. return;
  157. }
  158. }
  159. NSInteger firstVisibleSection = self.tableView.indexPathsForVisibleRows.firstObject.section;
  160. CGFloat insetTop = kSCIndexViewInsetTop;
  161. for (NSInteger section = firstVisibleSection; section < self.tableView.numberOfSections; section++) {
  162. CGRect sectionFrame = [self.tableView rectForSection:section];
  163. if (sectionFrame.origin.y + sectionFrame.size.height - self.tableView.contentOffset.y > insetTop) {
  164. currentSection = section;
  165. break;
  166. }
  167. }
  168. BOOL selectSearchLayer = NO;
  169. if (currentSection == 0 && self.searchLayer && currentSection < self.tableView.numberOfSections) {
  170. CGRect sectionFrame = [self.tableView rectForSection:currentSection];
  171. selectSearchLayer = (sectionFrame.origin.y - self.tableView.contentOffset.y - insetTop) > 0;
  172. }
  173. if (selectSearchLayer) {
  174. currentSection = SCIndexViewSearchSection;
  175. }
  176. else {
  177. currentSection = currentSection - self.startSection;
  178. }
  179. self.currentSection = currentSection;
  180. }
  181. #pragma mark - Event Response
  182. - (void)onActionWithDidSelect
  183. {
  184. if ((self.currentSection < 0 && self.currentSection != SCIndexViewSearchSection)
  185. || self.currentSection >= (NSInteger)self.subTextLayers.count) {
  186. return;
  187. }
  188. CGFloat insetTop = kSCIndexViewInsetTop;
  189. if (self.currentSection == SCIndexViewSearchSection) {
  190. [self.tableView setContentOffset:CGPointMake(0, -insetTop) animated:NO];
  191. } else {
  192. NSInteger currentSection = self.currentSection + self.startSection;
  193. if (currentSection >= 0 && currentSection < self.tableView.numberOfSections) {
  194. NSUInteger rowCountInSection = [self.tableView numberOfRowsInSection:currentSection];
  195. if (rowCountInSection > 0) {
  196. NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:currentSection];
  197. [self.tableView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionTop animated:NO];
  198. }
  199. }
  200. }
  201. if (self.isTouchingIndexView) {
  202. if (@available(iOS 10.0, *)) {
  203. [self.generator prepare];
  204. [self.generator impactOccurred];
  205. }
  206. }
  207. }
  208. - (void)onActionWithScroll
  209. {
  210. if (self.isTouchingIndexView) {
  211. // 当滑动tableView视图时,另一手指滑动索引视图,让tableView滑动失效
  212. self.tableView.panGestureRecognizer.enabled = NO;
  213. self.tableView.panGestureRecognizer.enabled = YES;
  214. return; // 当滑动索引视图时,tableView滚动不能影响索引位置
  215. }
  216. [self configCurrentSection];
  217. }
  218. #pragma mark - Display
  219. - (UIBezierPath *)drawIndicatorPath
  220. {
  221. CGFloat indicatorRadius = self.configuration.indicatorHeight / 2;
  222. CGFloat sinPI_4_Radius = sin(M_PI_4) * indicatorRadius;
  223. CGFloat margin = (sinPI_4_Radius * 2 - indicatorRadius);
  224. CGPoint startPoint = CGPointMake(margin + indicatorRadius + sinPI_4_Radius, indicatorRadius - sinPI_4_Radius);
  225. CGPoint trianglePoint = CGPointMake(4 * sinPI_4_Radius, indicatorRadius);
  226. CGPoint centerPoint = CGPointMake(margin + indicatorRadius, indicatorRadius);
  227. UIBezierPath *bezierPath = [UIBezierPath bezierPath];
  228. [bezierPath moveToPoint:startPoint];
  229. [bezierPath addArcWithCenter:centerPoint radius:indicatorRadius startAngle:-M_PI_4 endAngle:M_PI_4 clockwise:NO];
  230. [bezierPath addLineToPoint:trianglePoint];
  231. [bezierPath addLineToPoint:startPoint];
  232. [bezierPath closePath];
  233. return bezierPath;
  234. }
  235. - (CAShapeLayer *)createSearchLayer
  236. {
  237. CGFloat radius = self.configuration.indexItemHeight / 4;
  238. CGFloat margin = self.configuration.indexItemHeight / 4;
  239. CGFloat start = radius * 2.5 + margin;
  240. CGFloat end = radius + sin(M_PI_4) * radius + margin;
  241. UIBezierPath *path = [UIBezierPath bezierPath];
  242. [path moveToPoint:CGPointMake(start, start)];
  243. [path addLineToPoint:CGPointMake(end, end)];
  244. [path addArcWithCenter:CGPointMake(radius + margin, radius + margin) radius:radius startAngle:M_PI_4 endAngle:2 * M_PI + M_PI_4 clockwise:YES];
  245. [path closePath];
  246. CAShapeLayer *layer = [CAShapeLayer layer];
  247. layer.fillColor = self.configuration.indexItemBackgroundColor.CGColor;
  248. layer.strokeColor = self.configuration.indexItemTextColor.CGColor;
  249. layer.contentsScale = [UIScreen mainScreen].scale;
  250. layer.lineWidth = self.configuration.indexItemHeight / 12;
  251. layer.path = path.CGPath;
  252. return layer;
  253. }
  254. - (void)showIndicator:(BOOL)animated
  255. {
  256. if (self.currentSection >= (NSInteger)self.subTextLayers.count) return;
  257. if (self.currentSection < 0) {
  258. if (self.currentSection == SCIndexViewSearchSection) {
  259. [self hideIndicator:animated];
  260. }
  261. return;
  262. }
  263. SCTextLayer *textLayer = self.subTextLayers[self.currentSection];
  264. if (self.configuration.indexViewStyle == SCIndexViewStyleDefault) {
  265. self.indicator.center = CGPointMake(self.bounds.size.width - self.indicator.bounds.size.width / 2 - self.configuration.indicatorRightMargin, textLayer.position.y);
  266. } else {
  267. self.indicator.center = CGPointMake(self.bounds.size.width / 2, self.bounds.size.height / 2);
  268. }
  269. self.indicator.text = textLayer.string;
  270. if (animated) {
  271. self.indicator.alpha = 0;
  272. self.indicator.hidden = NO;
  273. [UIView animateWithDuration:kAnimationDuration animations:^{
  274. self.indicator.alpha = 1;
  275. }];
  276. } else {
  277. self.indicator.alpha = 1;
  278. self.indicator.hidden = NO;
  279. }
  280. }
  281. - (void)hideIndicator:(BOOL)animated
  282. {
  283. if (self.indicator.hidden) return;
  284. if (animated) {
  285. self.indicator.alpha = 1;
  286. self.indicator.hidden = NO;
  287. [UIView animateWithDuration:kAnimationDuration animations:^{
  288. self.indicator.alpha = 0;
  289. } completion:^(BOOL finished) {
  290. self.indicator.alpha = 1;
  291. self.indicator.hidden = YES;
  292. }];
  293. } else {
  294. self.indicator.alpha = 1;
  295. self.indicator.hidden = YES;
  296. }
  297. }
  298. - (void)refreshTextLayer:(BOOL)selected
  299. {
  300. if (self.currentSection < 0 || self.currentSection >= (NSInteger)self.subTextLayers.count) return;
  301. SCTextLayer *textLayer = self.subTextLayers[self.currentSection];
  302. UIColor *backgroundColor, *foregroundColor;
  303. UIFont *font;
  304. if (selected) {
  305. backgroundColor = self.configuration.indexItemSelectedBackgroundColor;
  306. foregroundColor = self.configuration.indexItemSelectedTextColor;
  307. font = self.configuration.indexItemSelectedTextFont;
  308. } else {
  309. backgroundColor = self.configuration.indexItemBackgroundColor;
  310. foregroundColor = self.configuration.indexItemTextColor;
  311. font = self.configuration.indexItemTextFont;
  312. }
  313. [CATransaction begin];
  314. [CATransaction setDisableActions:YES];
  315. textLayer.backgroundColor = backgroundColor.CGColor;
  316. textLayer.foregroundColor = foregroundColor.CGColor;
  317. textLayer.itemFont = font;
  318. [CATransaction commit];
  319. }
  320. #pragma mark - UITouch and UIEvent
  321. - (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event
  322. {
  323. // 当滑动索引视图时,防止其他手指去触发事件
  324. if (self.touchingIndexView) return YES;
  325. CALayer *firstLayer = self.searchLayer ?: self.subTextLayers.firstObject;
  326. if (!firstLayer) return NO;
  327. CALayer *lastLayer = self.subTextLayers.lastObject ?: self.searchLayer;
  328. if (!lastLayer) return NO;
  329. CGFloat space = self.configuration.indexItemRightMargin * 2;
  330. if (point.x > self.bounds.size.width - space - self.configuration.indexItemHeight
  331. && point.x <= self.bounds.size.width
  332. && point.y > CGRectGetMinY(firstLayer.frame) - space
  333. && point.y < CGRectGetMaxY(lastLayer.frame) + space) {
  334. return YES;
  335. }
  336. return NO;
  337. }
  338. - (BOOL)beginTrackingWithTouch:(UITouch *)touch withEvent:(UIEvent *)event
  339. {
  340. self.touchingIndexView = YES;
  341. CGPoint location = [touch locationInView:self];
  342. NSInteger currentPosition = SCPositionOfTextLayerInY(location.y, kSCIndexViewMargin, kSCIndexViewSpace);
  343. if (currentPosition < 0 || currentPosition >= (NSInteger)self.dataSource.count) return YES;
  344. NSInteger deta = self.searchLayer ? 1 : 0;
  345. NSInteger currentSection = currentPosition - deta;
  346. self.currentSection = currentSection;
  347. [self showIndicator:YES];
  348. [self onActionWithDidSelect];
  349. if (self.delegate && [self.delegate respondsToSelector:@selector(indexView:didSelectAtSection:)]) {
  350. [self.delegate indexView:self didSelectAtSection:self.currentSection];
  351. }
  352. return YES;
  353. }
  354. - (BOOL)continueTrackingWithTouch:(UITouch *)touch withEvent:(UIEvent *)event
  355. {
  356. self.touchingIndexView = YES;
  357. CGPoint location = [touch locationInView:self];
  358. NSInteger currentPosition = SCPositionOfTextLayerInY(location.y, kSCIndexViewMargin, kSCIndexViewSpace);
  359. if (currentPosition < 0) {
  360. currentPosition = 0;
  361. } else if (currentPosition >= (NSInteger)self.dataSource.count) {
  362. currentPosition = self.dataSource.count - 1;
  363. }
  364. NSInteger deta = self.searchLayer ? 1 : 0;
  365. NSInteger currentSection = currentPosition - deta;
  366. if (currentSection == self.currentSection) return YES;
  367. self.currentSection = currentSection;
  368. [self showIndicator:NO];
  369. [self onActionWithDidSelect];
  370. if (self.delegate && [self.delegate respondsToSelector:@selector(indexView:didSelectAtSection:)]) {
  371. [self.delegate indexView:self didSelectAtSection:self.currentSection];
  372. }
  373. return YES;
  374. }
  375. - (void)endTrackingWithTouch:(UITouch *)touch withEvent:(UIEvent *)event
  376. {
  377. self.touchingIndexView = NO;
  378. NSInteger oldCurrentPosition = self.currentSection;
  379. [self refreshCurrentSection];
  380. if (oldCurrentPosition != self.currentSection) {
  381. [self showIndicator:NO];
  382. }
  383. [self hideIndicator:YES];
  384. }
  385. - (void)cancelTrackingWithEvent:(UIEvent *)event
  386. {
  387. self.touchingIndexView = NO;
  388. NSInteger oldCurrentPosition = self.currentSection;
  389. [self refreshCurrentSection];
  390. if (oldCurrentPosition != self.currentSection) {
  391. [self showIndicator:NO];
  392. }
  393. [self hideIndicator:YES];
  394. }
  395. #pragma mark - Getters and Setters
  396. - (void)setDataSource:(NSArray<NSString *> *)dataSource
  397. {
  398. if (_dataSource == dataSource) return;
  399. _dataSource = dataSource.copy;
  400. [self configSubLayersAndSubviews];
  401. [self configCurrentSection];
  402. }
  403. - (void)setCurrentSection:(NSInteger)currentSection
  404. {
  405. if (currentSection == _currentSection) return;
  406. if ((currentSection < 0 && currentSection != SCIndexViewSearchSection)
  407. || currentSection >= (NSInteger)self.subTextLayers.count) {
  408. [self refreshTextLayer:NO];
  409. return;
  410. }
  411. [self refreshTextLayer:NO];
  412. _currentSection = currentSection;
  413. [self refreshTextLayer:YES];
  414. }
  415. - (void)setStartSection:(NSUInteger)startSection {
  416. if (_startSection == startSection) return;
  417. _startSection = startSection;
  418. [self configCurrentSection];
  419. }
  420. - (NSMutableArray *)subTextLayers
  421. {
  422. if (!_subTextLayers) {
  423. _subTextLayers = [NSMutableArray array];
  424. }
  425. return _subTextLayers;
  426. }
  427. - (UILabel *)indicator
  428. {
  429. if (!_indicator) {
  430. _indicator = [UILabel new];
  431. _indicator.layer.backgroundColor = self.configuration.indicatorBackgroundColor.CGColor;
  432. _indicator.textColor = self.configuration.indicatorTextColor;
  433. _indicator.font = self.configuration.indicatorTextFont;
  434. _indicator.textAlignment = NSTextAlignmentCenter;
  435. _indicator.hidden = YES;
  436. switch (self.configuration.indexViewStyle) {
  437. case SCIndexViewStyleDefault:
  438. {
  439. CGFloat indicatorRadius = self.configuration.indicatorHeight / 2;
  440. CGFloat sinPI_4_Radius = sin(M_PI_4) * indicatorRadius;
  441. _indicator.bounds = CGRectMake(0, 0, (4 * sinPI_4_Radius), 2 * indicatorRadius);
  442. CAShapeLayer *maskLayer = [CAShapeLayer layer];
  443. maskLayer.path = [self drawIndicatorPath].CGPath;
  444. _indicator.layer.mask = maskLayer;
  445. }
  446. break;
  447. case SCIndexViewStyleCenterToast:
  448. {
  449. _indicator.bounds = CGRectMake(0, 0, self.configuration.indicatorHeight, self.configuration.indicatorHeight);
  450. _indicator.center = CGPointMake(self.bounds.size.width / 2, self.bounds.size.height / 2);
  451. _indicator.layer.cornerRadius = self.configuration.indicatorCornerRadius;
  452. }
  453. break;
  454. default:
  455. break;
  456. }
  457. }
  458. return _indicator;
  459. }
  460. - (UIImpactFeedbackGenerator *)generator {
  461. if (!_generator) {
  462. _generator = [[UIImpactFeedbackGenerator alloc] initWithStyle:UIImpactFeedbackStyleLight];
  463. }
  464. return _generator;
  465. }
  466. @end