cdts/xdts-ios 3/TreeHole/CYHResetCode/Home(首页)/View/THLanternScrollView.m

105 lines
3.1 KiB
Mathematica
Raw Permalink Normal View History

2023-07-27 09:20:00 +08:00
//
// THLanternScrollView.m
// TreeHole
//
// Created by iOS on 2023/2/14.
// Copyright © 2023 CYH. All rights reserved.
//
#import "THLanternScrollView.h"
#import "THLanternScrollItemView.h"
@interface THLanternScrollView ()<UIScrollViewDelegate>
@property(nonatomic, strong)THLanternScrollItemView *firsItemView;
@property(nonatomic, strong)THLanternScrollItemView *secondItemView;
//@property(nonatomic, strong)THLanternScrollItemView *thirdItemView;
@property(nonatomic, strong)CADisplayLink *displayLink;
@property(nonatomic, assign)CGFloat offsetY;
@end
@implementation THLanternScrollView
- (void)setItemTapBlock:(void (^)(UIControl *))itemTapBlock {
_itemTapBlock = itemTapBlock;
self.firsItemView.itemTapBlock = itemTapBlock;
self.secondItemView.itemTapBlock = itemTapBlock;
}
- (void)starScrollAnimate {
if (self.displayLink && self.displayLink.paused) {
self.displayLink.paused = NO;
}
//
}
- (void)stopScrollAnimate {
self.displayLink.paused = YES;
// [self.scrollView setContentOffset:CGPointZero animated:NO];
}
- (void)scrollToAnimate {
// NSLog(@"000===%.2f", self.scrollView.contentOffset.y);
self.offsetY += 1;
self.scrollView.contentOffset = CGPointMake(0, self.offsetY);
// NSLog(@"y===%.2f", self.scrollView.contentOffset.y);
}
//MARK: UIScrollViewDelegate
- (void)scrollViewDidScroll:(UIScrollView *)scrollView; {
CGFloat itemW = scrollView.qmui_width;
CGFloat itemH = itemW / (1125.0/4872.0);
// NSLog(@"scrollContentOffsetY == %.2f", scrollView.contentOffset.y);
if (scrollView.contentOffset.y > (itemH * 1)) {
self.offsetY = 0;
self.scrollView.contentOffset = CGPointMake(0, 0);
// [self.scrollView setContentOffset:CGPointZero animated:NO];
return;
}
// if (scrollView.contentOffset.y > (itemW * 1.5)) {
// self.firsItemView.qmui_top = self.thirdItemView.qmui_bottom;
// }
}
//MARK: - life
- (void)setupSubViews {
_displayLink = [CADisplayLink displayLinkWithTarget:self selector:@selector(scrollToAnimate)];
_displayLink.paused = YES;
[_displayLink addToRunLoop:[NSRunLoop currentRunLoop] forMode:NSRunLoopCommonModes];
_scrollView = [UIScrollView creatViewInSuperView:self];
_scrollView.showsVerticalScrollIndicator = NO;
_scrollView.delegate = self;
_scrollView.scrollEnabled = NO;
_firsItemView = [THLanternScrollItemView creatViewInSuperView:_scrollView];
_secondItemView = [THLanternScrollItemView creatViewInSuperView:_scrollView];
// _thirdItemView = [THLanternScrollItemView creatViewInSuperView:_scrollView];
}
- (void)layoutSubviews {
[super layoutSubviews];
self.scrollView.frame = self.bounds;
// 1125x4872
CGFloat itemW = self.qmui_width;
CGFloat itemH = itemW / (1125.0/4872.0);
self.firsItemView.frame = CGRectMake(0, 0, itemW, itemH);
self.secondItemView.frame = CGRectMake(0, itemH, itemW, itemH);
//
// self.thirdItemView.frame = CGRectMake(0, itemH * 2, itemW, itemH);
self.scrollView.contentSize = CGSizeMake(0, itemH * 3);
}
@end