123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- //
- // BuyLimitSegmentManager.m
- // YouHuiProject
- //
- // Created by 小花 on 2018/7/6.
- // Copyright © 2018年 kuxuan. All rights reserved.
- //
- #import "BuyLimitSegmentManager.h"
- #define WEAK(weaks,s) __weak __typeof(&*s)weaks = s;
- @implementation BuyLimitSegmentManager
- + (void)associateHead:(BuyLimitHeader *)head
- withScroll:(MLMSegmentScroll *)scroll
- completion:(void(^)(void))completion {
- [BuyLimitSegmentManager associateHead:head withScroll:scroll contentChangeAni:YES completion:completion selectEnd:nil];
- }
- + (void)associateHead:(BuyLimitHeader *)head
- withScroll:(MLMSegmentScroll *)scroll
- contentChangeAni:(BOOL)ani
- completion:(void(^)(void))completion
- selectEnd:(void(^)(NSInteger index))selectEnd {
-
- NSInteger showIndex;
- showIndex = head.showIndex?head.showIndex:scroll.showIndex;
-
- head.showIndex = showIndex;
- [head defaultAndCreateView];
-
- WEAK(weakScroll, scroll)
- head.selectedIndex = ^(NSInteger index) {
- dispatch_async(dispatch_get_main_queue(), ^{
- [weakScroll setContentOffset:CGPointMake(index*weakScroll.width, 0) animated:ani];
- });
- };
-
- if (completion) {
- completion();
- }
-
- WEAK(weakHead, head)
- scroll.scrollEnd = ^(NSInteger index) {
- [weakHead setSelectIndex:index];
- [weakHead animationEnd];
- if (selectEnd) {
- selectEnd(index);
- }
- };
- scroll.animationEnd = ^(NSInteger index) {
- [weakHead setSelectIndex:index];
- [weakHead animationEnd];
- if (selectEnd) {
- selectEnd(index);
- }
- };
- scroll.offsetScale = ^(CGFloat scale) {
- [weakHead changePointScale:scale];
- };
-
-
- scroll.showIndex = showIndex;
- [scroll createView];
-
- UIView *view = head.nextResponder?head:scroll;
- UIViewController *currentVC = [view viewController];
- currentVC.automaticallyAdjustsScrollViewInsets = NO;
- }
- @end
|