口袋优选

BuyLimitSegmentManager.m 2.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. //
  2. // BuyLimitSegmentManager.m
  3. // YouHuiProject
  4. //
  5. // Created by 小花 on 2018/7/6.
  6. // Copyright © 2018年 kuxuan. All rights reserved.
  7. //
  8. #import "BuyLimitSegmentManager.h"
  9. #define WEAK(weaks,s) __weak __typeof(&*s)weaks = s;
  10. @implementation BuyLimitSegmentManager
  11. + (void)associateHead:(BuyLimitHeader *)head
  12. withScroll:(MLMSegmentScroll *)scroll
  13. completion:(void(^)(void))completion {
  14. [BuyLimitSegmentManager associateHead:head withScroll:scroll contentChangeAni:YES completion:completion selectEnd:nil];
  15. }
  16. + (void)associateHead:(BuyLimitHeader *)head
  17. withScroll:(MLMSegmentScroll *)scroll
  18. contentChangeAni:(BOOL)ani
  19. completion:(void(^)(void))completion
  20. selectEnd:(void(^)(NSInteger index))selectEnd {
  21. NSInteger showIndex;
  22. showIndex = head.showIndex?head.showIndex:scroll.showIndex;
  23. head.showIndex = showIndex;
  24. [head defaultAndCreateView];
  25. WEAK(weakScroll, scroll)
  26. head.selectedIndex = ^(NSInteger index) {
  27. dispatch_async(dispatch_get_main_queue(), ^{
  28. [weakScroll setContentOffset:CGPointMake(index*weakScroll.width, 0) animated:ani];
  29. });
  30. };
  31. if (completion) {
  32. completion();
  33. }
  34. WEAK(weakHead, head)
  35. scroll.scrollEnd = ^(NSInteger index) {
  36. [weakHead setSelectIndex:index];
  37. [weakHead animationEnd];
  38. if (selectEnd) {
  39. selectEnd(index);
  40. }
  41. };
  42. scroll.animationEnd = ^(NSInteger index) {
  43. [weakHead setSelectIndex:index];
  44. [weakHead animationEnd];
  45. if (selectEnd) {
  46. selectEnd(index);
  47. }
  48. };
  49. scroll.offsetScale = ^(CGFloat scale) {
  50. [weakHead changePointScale:scale];
  51. };
  52. scroll.showIndex = showIndex;
  53. [scroll createView];
  54. UIView *view = head.nextResponder?head:scroll;
  55. UIViewController *currentVC = [view viewController];
  56. currentVC.automaticallyAdjustsScrollViewInsets = NO;
  57. }
  58. @end