// // SPSBGuideViewController.m // 我的社保 // // Created by shanp on 2021/4/29. // #import "SPSBGuideViewController.h" #import "SPSBUIGeneralHeader.h" @interface SPSBGuideViewController () { UIView *_pageControlView; UIView *_pageControl; UIView *_leftView; UIView *_rightView; bool _scrollLeft; UIButton *_nextButton; } @end @implementation SPSBGuideViewController - (void)viewDidLoad { [super viewDidLoad]; [self setupUI]; } #pragma mark - Action - (void)nextAction { if (_spsb_nextAction) { _spsb_nextAction(); } } #pragma mark - UIScrollViewDelegate - (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView { _scrollLeft = scrollView.contentOffset.x == 0; } - (void)scrollViewDidScroll:(UIScrollView *)scrollView { if (scrollView.contentOffset.x < jxh_screenWidth()) { _nextButton.hidden = true; } else { _nextButton.hidden = false; _nextButton.layer.transform = CATransform3DMakeScale(0.001, 0.001, 1); [UIView animateWithDuration:0.2 animations:^{ // 按照比例scalex=0.001,y=0.001进行缩小 self -> _nextButton.layer.transform = CATransform3DMakeScale(1, 1, 1); }]; } if (scrollView.contentOffset.x / jxh_screenWidth() >= 0 && scrollView.contentOffset.x / jxh_screenWidth() <= 1) { [_pageControl makeConstraints:^(JXHConstraintMaker *make) { make.leading.update(scrollView.contentOffset.x / jxh_screenWidth() * 18); }]; } if (_scrollLeft) { _leftView.hidden = false; _rightView.hidden = scrollView.contentOffset.x > 0; } else { _rightView.hidden = false; _leftView.hidden = scrollView.contentOffset.x < jxh_screenWidth(); } } #pragma mark - Network Action #pragma mark - UI - (void)setupUI { UIScrollView *guidanceScrollView = [UIScrollView convenienceWithBackgroundColor:spsb_FFFFFF_color(1.f)]; guidanceScrollView.delegate = self; guidanceScrollView.bounces = false; guidanceScrollView.pagingEnabled = true; [self.view addSubview:guidanceScrollView]; [guidanceScrollView makeConstraints:^(JXHConstraintMaker *make) { make.edges.equalTo(self.view); }]; UIView *bgView = UIView.new; [guidanceScrollView addSubview:bgView]; [bgView makeConstraints:^(JXHConstraintMaker *make) { make.edges.equalTo(guidanceScrollView); make.size.equalTo(CGSizeMake(jxh_screenWidth() * 2, jxh_screenHeight())); }]; for (NSInteger i = 0; i < 2; i ++) { NSString *imageName = [NSString stringWithFormat:@"guide_w_%ld", (long)i + 1]; UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:imageName]]; [guidanceScrollView addSubview:imageView]; [imageView makeConstraints:^(JXHConstraintMaker *make) { make.centerX.equalTo(guidanceScrollView).offset(jxh_screenWidth() * i); make.size.equalTo(CGSizeMake(jxh_screenWidth(), 0.16 * jxh_screenWidth())); if (jxh_screenHeight() == 480) { make.top.equalTo(50); } else if (jxh_screenHeight() == 896) { if (@available(iOS 11.0, *)) { make.top.equalTo(self.view.safetop).offset(jxh_navigationViewHeight() + 60); } else { make.top.equalTo(self.view.top).offset(jxh_navigationViewHeight() + jxh_statusBarHeight() + 60); } } else { if (@available(iOS 11.0, *)) { make.top.equalTo(self.view.safetop).offset(jxh_navigationViewHeight() + 10); } else { make.top.equalTo(self.view.top).offset(jxh_navigationViewHeight() + jxh_statusBarHeight() + 10); } } }]; imageName = [NSString stringWithFormat:@"guide_%ld", (long)i + 1]; imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:imageName]]; [guidanceScrollView addSubview:imageView]; [imageView makeConstraints:^(JXHConstraintMaker *make) { make.centerX.equalTo(guidanceScrollView).offset(jxh_screenWidth() * i); make.size.equalTo(CGSizeMake(jxh_screenWidth(), 0.853 * jxh_screenWidth())); if (jxh_screenHeight() == 896) { if (@available(iOS 11.0, *)) { make.top.equalTo(self.view.safetop).offset(jxh_navigationViewHeight() + 60 + (jxh_screenHeight() - 480) * 0.25); } else { make.top.equalTo(self.view.top).offset(jxh_navigationViewHeight() + jxh_statusBarHeight() + 60 + (jxh_screenHeight() - 480) * 0.25); } } else { if (@available(iOS 11.0, *)) { make.top.equalTo(self.view.safetop).offset(jxh_navigationViewHeight() + 40 + (jxh_screenHeight() - 480) * 0.25); } else { make.top.equalTo(self.view.top).offset(jxh_navigationViewHeight() + jxh_statusBarHeight() + 40 + (jxh_screenHeight() - 480) * 0.25); } } }]; } _pageControlView = [[UIView alloc] init]; _pageControlView.backgroundColor = [UIColor whiteColor]; [self.view addSubview:_pageControlView]; [_pageControlView makeConstraints:^(JXHConstraintMaker *make) { make.centerX.equalTo(self.view); if (jxh_screenHeight() == 480) { make.bottom.equalTo(self.view.safebottom).offset(- 60); } else if (jxh_screenHeight() == 896) { make.bottom.equalTo(self.view.safebottom).offset(- 100); } else { make.bottom.equalTo(self.view.safebottom).offset(- 80); } make.height.equalTo(5); }]; _leftView = UIView.new; _leftView.backgroundColor = spsb_3296FB_4_color(); [_leftView setLayerCornerRadius:2.5 clipToBounds:false]; [_pageControlView addSubview:_leftView]; [_leftView makeConstraints:^(JXHConstraintMaker *make) { make.leading.and.top.and.bottom.equalTo(0); make.width.equalTo(10); }]; _rightView = UIView.new; _rightView.backgroundColor = spsb_3296FB_4_color(); [_rightView setLayerCornerRadius:2.5 clipToBounds:false]; [_pageControlView addSubview:_rightView]; [_rightView makeConstraints:^(JXHConstraintMaker *make) { make.trailing.and.top.and.bottom.equalTo(0); make.leading.equalTo(self -> _leftView.trailing).offset(8 + 14); make.width.equalTo(10); }]; _pageControl = UIView.new; _pageControl.backgroundColor = spsb_3296FB_color(); [_pageControl setLayerCornerRadius:2.5 clipToBounds:false]; [_pageControlView addSubview:_pageControl]; [_pageControl makeConstraints:^(JXHConstraintMaker *make) { make.leading.and.top.and.bottom.equalTo(0); make.width.equalTo(24); }]; _nextButton = [UIButton convenienceWithFont:spsb_semiboldFont(17) target:self action:@selector(nextAction)]; [_nextButton setTitle:@"立即体验" titleColor:spsb_FFFFFF_color(1.f) image:nil backgroundImage:jxh_getImage(confirm_n) state:JXHButtonControlStateNormal]; [_nextButton setBackgroundImage:jxh_getImage(confirm_h) state:JXHButtonControlStateHighlighted]; _nextButton.hidden = true; [_nextButton setLayerCornerRadius:25 clipToBounds:true]; [self.view addSubview:_nextButton]; [_nextButton makeConstraints:^(JXHConstraintMaker *make) { make.leading.equalTo(48); make.trailing.equalTo(-48); make.height.equalTo(50); make.centerY.equalTo(self -> _pageControlView); }]; } @end