181

GitHub - gltwy/LTScrollView: ScrollView嵌套ScrolloView(UITableView 、UICollecti...

 5 years ago
source link: https://github.com/gltwy/LTScrollView
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

README.md

LTScrollView

实现原理: http://blog.csdn.net/glt_code/article/details/78576628

CI Status Version License Platform

image

Example

  • LTScrollView / Example : 为 Swift 使用示例.
  • LTScrollView / OCExample : 为 OC 使用示例.

Installation with CocoaPods

CocoaPods is a dependency manager for Swift, which automates and simplifies the process of using 3rd-party libraries like LTScrollView in your projects. You can install it with the following command:

$ gem install cocoapods

Podfile

To integrate LTScrollView into your Xcode project using CocoaPods, specify it in your Podfile:

source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '8.0'

target 'TargetName' do
pod 'LTScrollView', '~> 0.1.7'
end

Then, run the following command:

$ pod install

提示错误 [!] Unable to find a specification for LTScrollView 解决办法:

$ pod repo remove master
$ pod setup

Usage

Swift使用说明

Swift.LTSimple使用说明
1. 创建LTSimpleManager实例对象
@objc public init(frame: CGRect, viewControllers: [UIViewController], titles: [String], currentViewController:UIViewController, layout: LTLayout)

2. 设置headerView
@objc public func configHeaderView(_ handle: (() -> UIView?)?)

3. 子控制器中glt_scrollView进行赋值
self.glt_scrollView = self.tableViewself.scrollView / self.collectionView
Swift.LTAdvanced使用说明
private lazy var layout: LTLayout = {
    let layout = LTLayout()
    return layout
}()

private lazy var advancedManager: LTAdvancedManager = {
    let advancedManager = LTAdvancedManager(frame: frame, viewControllers: viewControllers, titles: titles, currentViewController: self, layout: layout, headerViewHandle: {[weak self] in
        guard let strongSelf = self else { return UIView() }
        let headerView = strongSelf.testLabel()
        return headerView
    })
         /* 设置代理 监听滚动 */
        advancedManager.delegate = self
        
        /* 设置悬停位置 */
        advancedManager.hoverY = 64
        
        /* 点击切换滚动过程动画 */
        advancedManager.isClickScrollAnimation = true
        
        /* 代码设置滚动到第几个位置 */
        advancedManager.scrollToIndex(index: viewControllers.count - 1)
        
    return advancedManager
}()

//MARK: 选中事件
advancedManager.advancedDidSelectIndexHandle = {
    print($0)
}

//MARK: 滚动代理方法监听
func glt_scrollViewOffsetY(_ offsetY: CGFloat) {
    print("offset --> ", offsetY)
}

OC使用说明

OC.LTSimple使用说明
-(LTSimpleManager *)managerView {
    if (!_managerView) {
        _managerView = [[LTSimpleManager alloc] initWithFrame:frame viewControllers:self.viewControllers titles:self.titles currentViewController:self layout:self.layout];
        
        /* 设置代理 监听滚动 */
        _managerView.delegate = self;
        
        /* 设置悬停位置 */
//        _managerView.hoverY = 64;
        
        /* 点击切换滚动过程动画 */
//        _managerView.isClickScrollAnimation = YES;
        
        /* 代码设置滚动到第几个位置 */
//        [_managerView scrollToIndexWithIndex:self.viewControllers.count - 1];
    }
    return _managerView;
}
    
//配置headerView
[self.managerView configHeaderView:^UIView * _Nullable{
    return [weakSelf setupHeaderView];
}];

//pageView点击事件
[self.managerView didSelectIndexHandle:^(NSInteger index) {
    NSLog(@"点击了 -> %ld", index);
}];

//滚动代理方法监听
-(void)glt_scrollViewDidScroll:(UIScrollView *)scrollView {
    NSLog(@"---> %lf", scrollView.contentOffset.y);
}

//控制器刷新事件
[self.managerView refreshTableViewHandle:^(UIScrollView * _Nonnull scrollView, NSInteger index) {
    __weak typeof(scrollView) weakScrollView = scrollView;
    scrollView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
        __strong typeof(weakScrollView) strongScrollView = weakScrollView;
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            NSLog(@"对应控制器的刷新自己玩吧,这里就不做处理了?-----%ld", index);
            [strongScrollView.mj_header endRefreshing];
        });
    }];
}];
OC.LTAdvanced使用说明
-(LTAdvancedManager *)managerView {
    if (!_managerView) {
        _managerView = [[LTAdvancedManager alloc] initWithFrame:CGRectMake(0, Y, self.view.bounds.size.width, H) viewControllers:self.viewControllers titles:self.titles currentViewController:self layout:self.layout headerViewHandle:^UIView * _Nonnull{
            return [self setupHeaderView];
        }];
        /* 设置代理 监听滚动 */
        _managerView.delegate = self;
        
        /* 设置悬停位置 */
//        _managerView.hoverY = 64;
        
        /* 点击切换滚动过程动画 */
        _managerView.isClickScrollAnimation = YES;
        
        /* 代码设置滚动到第几个位置 */
        [_managerView scrollToIndexWithIndex:self.viewControllers.count - 1];
    }
    return _managerView;
}

//滚动代理方法监听
-(void)glt_scrollViewOffsetY:(CGFloat)offsetY {
    NSLog(@"---> %lf", offsetY);
}

[self.managerView setAdvancedDidSelectIndexHandle:^(NSInteger index) {
    NSLog(@"%ld", index);
}];

LTLayout属性说明

public class LTLayout: NSObject {
    
    /* pageView背景颜色 */
    @objc public var titleViewBgColor: UIColor? = UIColor.gray
    
    /* 标题颜色,请使用RGB赋值 */
    @objc public var titleColor: UIColor? = NORMAL_BASE_COLOR
    
    /* 标题选中颜色,请使用RGB赋值 */
    @objc public var titleSelectColor: UIColor? = SELECT_BASE_COLOR
    
    /* 标题字号 */
    @objc public var titleFont: UIFont? = UIFont.systemFont(ofSize: 16)
    
    /* 滑块底部线的颜色 */
    @objc public var bottomLineColor: UIColor? = UIColor.blue
    
    /* 整个滑块的高,pageTitleView的高 */
    @objc public var sliderHeight: CGFloat = 44.0
    
    /* 单个滑块的宽度, 一旦设置,将不再自动计算宽度,而是固定为你传递的值 */
    @objc public var sliderWidth: CGFloat = glt_sliderDefaultWidth
    
    /*
     * 如果刚开始的布局不希望从最左边开始, 只想平均分配在整个宽度中,设置它为true
     * 注意:此时最左边 lrMargin 以及 titleMargin 仍然有效,如果不需要可以手动设置为0
     */
    @objc public var isAverage: Bool = false
    
    /* 滑块底部线的高 */
    @objc public var bottomLineHeight: CGFloat = 2.0
    
    /* 滑块底部线圆角 */
    @objc public var bottomLineCornerRadius: CGFloat = 0.0
    
    /* 是否隐藏滑块 */
    @objc public var isHiddenSlider: Bool = false
    
    /* 标题直接的间隔(标题距离下一个标题的间隔)*/
    @objc public var titleMargin: CGFloat = 30.0
    
    /* 距离最左边和最右边的距离 */
    @objc public var lrMargin: CGFloat = 10.0
    
    /* 滑动过程中是否放大标题 */
    @objc public var isNeedScale: Bool = true
    
    /* 放大标题的倍率 */
    @objc public var scale: CGFloat = 1.2
    
    /* 是否开启颜色渐变 */
    @objc public var isColorAnimation: Bool = true
    
    /* 是否隐藏底部线 */
    @objc public var isHiddenPageBottomLine: Bool = false
    
    /* pageView底部线的高度 */
    @objc public var pageBottomLineHeight: CGFloat = 0.5
    
    /* pageView底部线的颜色 */
    @objc public var pageBottomLineColor: UIColor? = UIColor.gray
    
    
}

更新说明

2018.06.30 - 0.1.7

1. 修复LTAdvancedManager数据较少时,其他子控制器自动下落Bug
2. 解决issue中的部分问题
3. 优化内部实现

2018.06.02 - 0.1.6

1. 修复LTSimple当HeaderView的高度为小数时无法滑动的Bug
2. 增加代码设置滚动位置的方法
3. 增加切换动画属性设置
4. 修复已知Bug

2018.05.12 - 0.1.5

1. 修复循环引用导致控制器无法释放的问题
2. 可手动设置悬停PageTitleView的位置(y值)
3. 修复了LTAdvanced的已知Bug

Author

[email protected]

License

LTScrollView is available under the MIT license. See the LICENSE file for more info.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK