SPSBGuideViewController.m 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. //
  2. // SPSBGuideViewController.m
  3. // 我的社保
  4. //
  5. // Created by shanp on 2021/4/29.
  6. //
  7. #import "SPSBGuideViewController.h"
  8. #import "SPSBUIGeneralHeader.h"
  9. @interface SPSBGuideViewController ()<UIScrollViewDelegate> {
  10. UIView *_pageControlView;
  11. UIView *_pageControl;
  12. UIView *_leftView;
  13. UIView *_rightView;
  14. bool _scrollLeft;
  15. UIButton *_nextButton;
  16. }
  17. @end
  18. @implementation SPSBGuideViewController
  19. - (void)viewDidLoad {
  20. [super viewDidLoad];
  21. [self setupUI];
  22. }
  23. #pragma mark - Action
  24. - (void)nextAction {
  25. if (_spsb_nextAction) {
  26. _spsb_nextAction();
  27. }
  28. }
  29. #pragma mark - UIScrollViewDelegate
  30. - (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView {
  31. _scrollLeft = scrollView.contentOffset.x == 0;
  32. }
  33. - (void)scrollViewDidScroll:(UIScrollView *)scrollView {
  34. if (scrollView.contentOffset.x < jxh_screenWidth()) {
  35. _nextButton.hidden = true;
  36. } else {
  37. _nextButton.hidden = false;
  38. _nextButton.layer.transform = CATransform3DMakeScale(0.001, 0.001, 1);
  39. [UIView animateWithDuration:0.2 animations:^{
  40. // 按照比例scalex=0.001,y=0.001进行缩小
  41. self -> _nextButton.layer.transform = CATransform3DMakeScale(1, 1, 1);
  42. }];
  43. }
  44. if (scrollView.contentOffset.x / jxh_screenWidth() >= 0 && scrollView.contentOffset.x / jxh_screenWidth() <= 1) {
  45. [_pageControl makeConstraints:^(JXHConstraintMaker *make) {
  46. make.leading.update(scrollView.contentOffset.x / jxh_screenWidth() * 18);
  47. }];
  48. }
  49. if (_scrollLeft) {
  50. _leftView.hidden = false;
  51. _rightView.hidden = scrollView.contentOffset.x > 0;
  52. } else {
  53. _rightView.hidden = false;
  54. _leftView.hidden = scrollView.contentOffset.x < jxh_screenWidth();
  55. }
  56. }
  57. #pragma mark - Network Action
  58. #pragma mark - UI
  59. - (void)setupUI {
  60. UIScrollView *guidanceScrollView = [UIScrollView convenienceWithBackgroundColor:spsb_FFFFFF_color(1.f)];
  61. guidanceScrollView.delegate = self;
  62. guidanceScrollView.bounces = false;
  63. guidanceScrollView.pagingEnabled = true;
  64. [self.view addSubview:guidanceScrollView];
  65. [guidanceScrollView makeConstraints:^(JXHConstraintMaker *make) {
  66. make.edges.equalTo(self.view);
  67. }];
  68. UIView *bgView = UIView.new;
  69. [guidanceScrollView addSubview:bgView];
  70. [bgView makeConstraints:^(JXHConstraintMaker *make) {
  71. make.edges.equalTo(guidanceScrollView);
  72. make.size.equalTo(CGSizeMake(jxh_screenWidth() * 2, jxh_screenHeight()));
  73. }];
  74. for (NSInteger i = 0; i < 2; i ++) {
  75. NSString *imageName = [NSString stringWithFormat:@"guide_w_%ld", (long)i + 1];
  76. UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:imageName]];
  77. [guidanceScrollView addSubview:imageView];
  78. [imageView makeConstraints:^(JXHConstraintMaker *make) {
  79. make.centerX.equalTo(guidanceScrollView).offset(jxh_screenWidth() * i);
  80. make.size.equalTo(CGSizeMake(jxh_screenWidth(), 0.16 * jxh_screenWidth()));
  81. if (jxh_screenHeight() == 480) {
  82. make.top.equalTo(50);
  83. } else if (jxh_screenHeight() == 896) {
  84. if (@available(iOS 11.0, *)) {
  85. make.top.equalTo(self.view.safetop).offset(jxh_navigationViewHeight() + 60);
  86. } else {
  87. make.top.equalTo(self.view.top).offset(jxh_navigationViewHeight() + jxh_statusBarHeight() + 60);
  88. }
  89. } else {
  90. if (@available(iOS 11.0, *)) {
  91. make.top.equalTo(self.view.safetop).offset(jxh_navigationViewHeight() + 10);
  92. } else {
  93. make.top.equalTo(self.view.top).offset(jxh_navigationViewHeight() + jxh_statusBarHeight() + 10);
  94. }
  95. }
  96. }];
  97. imageName = [NSString stringWithFormat:@"guide_%ld", (long)i + 1];
  98. imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:imageName]];
  99. [guidanceScrollView addSubview:imageView];
  100. [imageView makeConstraints:^(JXHConstraintMaker *make) {
  101. make.centerX.equalTo(guidanceScrollView).offset(jxh_screenWidth() * i);
  102. make.size.equalTo(CGSizeMake(jxh_screenWidth(), 0.853 * jxh_screenWidth()));
  103. if (jxh_screenHeight() == 896) {
  104. if (@available(iOS 11.0, *)) {
  105. make.top.equalTo(self.view.safetop).offset(jxh_navigationViewHeight() + 60 + (jxh_screenHeight() - 480) * 0.25);
  106. } else {
  107. make.top.equalTo(self.view.top).offset(jxh_navigationViewHeight() + jxh_statusBarHeight() + 60 + (jxh_screenHeight() - 480) * 0.25);
  108. }
  109. } else {
  110. if (@available(iOS 11.0, *)) {
  111. make.top.equalTo(self.view.safetop).offset(jxh_navigationViewHeight() + 40 + (jxh_screenHeight() - 480) * 0.25);
  112. } else {
  113. make.top.equalTo(self.view.top).offset(jxh_navigationViewHeight() + jxh_statusBarHeight() + 40 + (jxh_screenHeight() - 480) * 0.25);
  114. }
  115. }
  116. }];
  117. }
  118. _pageControlView = [[UIView alloc] init];
  119. _pageControlView.backgroundColor = [UIColor whiteColor];
  120. [self.view addSubview:_pageControlView];
  121. [_pageControlView makeConstraints:^(JXHConstraintMaker *make) {
  122. make.centerX.equalTo(self.view);
  123. if (jxh_screenHeight() == 480) {
  124. make.bottom.equalTo(self.view.safebottom).offset(- 60);
  125. } else if (jxh_screenHeight() == 896) {
  126. make.bottom.equalTo(self.view.safebottom).offset(- 100);
  127. } else {
  128. make.bottom.equalTo(self.view.safebottom).offset(- 80);
  129. }
  130. make.height.equalTo(5);
  131. }];
  132. _leftView = UIView.new;
  133. _leftView.backgroundColor = spsb_3296FB_4_color();
  134. [_leftView setLayerCornerRadius:2.5 clipToBounds:false];
  135. [_pageControlView addSubview:_leftView];
  136. [_leftView makeConstraints:^(JXHConstraintMaker *make) {
  137. make.leading.and.top.and.bottom.equalTo(0);
  138. make.width.equalTo(10);
  139. }];
  140. _rightView = UIView.new;
  141. _rightView.backgroundColor = spsb_3296FB_4_color();
  142. [_rightView setLayerCornerRadius:2.5 clipToBounds:false];
  143. [_pageControlView addSubview:_rightView];
  144. [_rightView makeConstraints:^(JXHConstraintMaker *make) {
  145. make.trailing.and.top.and.bottom.equalTo(0);
  146. make.leading.equalTo(self -> _leftView.trailing).offset(8 + 14);
  147. make.width.equalTo(10);
  148. }];
  149. _pageControl = UIView.new;
  150. _pageControl.backgroundColor = spsb_3296FB_color();
  151. [_pageControl setLayerCornerRadius:2.5 clipToBounds:false];
  152. [_pageControlView addSubview:_pageControl];
  153. [_pageControl makeConstraints:^(JXHConstraintMaker *make) {
  154. make.leading.and.top.and.bottom.equalTo(0);
  155. make.width.equalTo(24);
  156. }];
  157. _nextButton = [UIButton convenienceWithFont:spsb_semiboldFont(17) target:self action:@selector(nextAction)];
  158. [_nextButton setTitle:@"立即体验" titleColor:spsb_FFFFFF_color(1.f) image:nil backgroundImage:jxh_getImage(confirm_n) state:JXHButtonControlStateNormal];
  159. [_nextButton setBackgroundImage:jxh_getImage(confirm_h) state:JXHButtonControlStateHighlighted];
  160. _nextButton.hidden = true;
  161. [_nextButton setLayerCornerRadius:25 clipToBounds:true];
  162. [self.view addSubview:_nextButton];
  163. [_nextButton makeConstraints:^(JXHConstraintMaker *make) {
  164. make.leading.equalTo(48);
  165. make.trailing.equalTo(-48);
  166. make.height.equalTo(50);
  167. make.centerY.equalTo(self -> _pageControlView);
  168. }];
  169. }
  170. @end