RQNewFeatureViewController.m 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. //
  2. // RQNewFeatureViewController.m
  3. // RQCommon
  4. //
  5. // Created by 张嵘 on 2018/11/23.
  6. // Copyright © 2018 张嵘. All rights reserved.
  7. //
  8. #import "RQNewFeatureViewController.h"
  9. #import "AppDelegate.h"
  10. @interface RQNewFeatureViewController () <UIScrollViewDelegate>
  11. /// 滚动视图
  12. @property (nonatomic, readwrite, strong) UIScrollView *scrollView;
  13. /// 分页控件
  14. @property (nonatomic, readwrite, strong) UIPageControl *pageControl;
  15. /// 开始按钮
  16. @property (nonatomic, readwrite, strong) UIButton *startButton;
  17. /// 分享微博
  18. @property (nonatomic, readwrite, strong) UIButton *sharedButton;
  19. /// viewModel
  20. @property (nonatomic, readwrite, strong) RQNewFeatureViewModel *viewModel;
  21. /// 图片数组
  22. @property (nonatomic, readwrite, copy) NSArray *imagesArr;
  23. @end
  24. @implementation RQNewFeatureViewController
  25. @dynamic viewModel;
  26. - (void)viewDidLoad {
  27. [super viewDidLoad];
  28. [self setupUI];
  29. }
  30. #pragma mark - 监听方法
  31. /// 点击开始按钮
  32. - (void)clickStartButton {
  33. [[NSNotificationCenter defaultCenter] postNotificationName:RQSwitchRootViewControllerNotification object:nil userInfo:@{RQSwitchRootViewControllerUserInfoKey:@(RQSwitchRootViewControllerFromTypeNewFeature)}];
  34. }
  35. - (void)clickSharedButton {
  36. self.sharedButton.selected = !self.sharedButton.selected;
  37. }
  38. #pragma mark - UIScrollViewDelegate
  39. /// UIScrollView 停止滚动
  40. - (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
  41. // 当前页数
  42. self.pageControl.currentPage = scrollView.contentOffset.x / scrollView.bounds.size.width;
  43. }
  44. #pragma mark - 设置界面
  45. - (void)setupUI {
  46. [self _prepareScrollView];
  47. [self _preparePageControl];
  48. [self _prepareLastPage];
  49. }
  50. /// 准备最后一页控件
  51. - (void)_prepareLastPage {
  52. UIImageView *imageView = self.scrollView.subviews.lastObject;
  53. imageView.userInteractionEnabled = YES;
  54. [imageView addSubview:self.startButton];
  55. // [imageView addSubview:self.sharedButton];
  56. [self.startButton mas_makeConstraints:^(MASConstraintMaker *make) {
  57. make.centerX.equalTo(imageView);
  58. make.bottom.mas_equalTo(-100);
  59. make.size.mas_equalTo(CGSizeMake(RQ_SCREEN_WIDTH / 2.f, 50.f));
  60. _startButton.layer.cornerRadius = 25.f;
  61. _startButton.clipsToBounds = YES;
  62. }];
  63. // [self.sharedButton mas_makeConstraints:^(MASConstraintMaker *make) {
  64. // make.centerX.equalTo(self.startButton);
  65. // make.bottom.mas_equalTo(self.startButton.mas_top).offset(-20);
  66. // }];
  67. }
  68. /// 准备分页控件
  69. - (void)_preparePageControl {
  70. [self.view addSubview:self.pageControl];
  71. self.pageControl.numberOfPages = self.imagesArr.count;
  72. self.pageControl.currentPage = 0;
  73. [self.pageControl mas_makeConstraints:^(MASConstraintMaker *make) {
  74. make.centerX.equalTo(self.view);
  75. make.bottom.equalTo(self.view).offset(-40);
  76. }];
  77. }
  78. /// 准备 UIScrollView
  79. - (void)_prepareScrollView {
  80. [self.view addSubview:self.scrollView];
  81. self.scrollView.frame = self.view.bounds;
  82. // 添加图像视图
  83. for (int i = 0; i < self.imagesArr.count; ++i) {
  84. UIImage *image = [UIImage imageNamed:self.imagesArr[i]];
  85. UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
  86. // 设置大小
  87. imageView.frame = CGRectOffset(self.view.bounds, i * self.view.bounds.size.width, 0);
  88. [self.scrollView addSubview:imageView];
  89. }
  90. // 设置 contentSize
  91. self.scrollView.contentSize = CGRectInset(self.view.bounds, -1.5 * self.view.bounds.size.width, 0).size;
  92. /// 适配 iOS11
  93. RQAdjustsScrollViewInsets_Never(self.scrollView);
  94. }
  95. #pragma mark - 懒加载控件
  96. - (UIScrollView *)scrollView {
  97. if (_scrollView == nil) {
  98. _scrollView = [[UIScrollView alloc] init];
  99. _scrollView.showsHorizontalScrollIndicator = NO;
  100. _scrollView.showsVerticalScrollIndicator = NO;
  101. _scrollView.bounces = NO;
  102. _scrollView.pagingEnabled = YES;
  103. _scrollView.delegate = self;
  104. }
  105. return _scrollView;
  106. }
  107. - (UIPageControl *)pageControl {
  108. if (_pageControl == nil) {
  109. _pageControl = [[UIPageControl alloc] init];
  110. _pageControl.pageIndicatorTintColor = [UIColor blackColor];
  111. _pageControl.currentPageIndicatorTintColor = RQ_MAIN_COLOR;
  112. // 提示:需要禁止用户交互,否则用户点击小圆点,会移动,但是页面不会变化
  113. _pageControl.userInteractionEnabled = NO;
  114. }
  115. return _pageControl;
  116. }
  117. - (UIButton *)startButton {
  118. if (_startButton == nil) {
  119. _startButton = [UIButton buttonWithType:UIButtonTypeCustom];
  120. [_startButton setTitle:@"进入主页" forState:UIControlStateNormal];
  121. [_startButton setTitleColor:UIColor.whiteColor forState:UIControlStateNormal];
  122. // [_startButton setBackgroundImage:RQImageNamed(@"new_feature_finish_button") forState:UIControlStateNormal];
  123. [_startButton setBackgroundColor:RQ_MAIN_COLOR];
  124. [_startButton addTarget:self action:@selector(clickStartButton) forControlEvents:UIControlEventTouchUpInside];
  125. }
  126. return _startButton;
  127. }
  128. - (UIButton *)sharedButton {
  129. if (_sharedButton == nil) {
  130. _sharedButton = [[UIButton alloc] init];
  131. [_sharedButton setTitle:@" 分享到微博" forState:UIControlStateNormal];
  132. [_sharedButton setTitleColor:[UIColor darkGrayColor] forState:UIControlStateNormal];
  133. [_sharedButton setImage:[UIImage imageNamed:@"new_feature_share_false"] forState:UIControlStateNormal];
  134. [_sharedButton setImage:[UIImage imageNamed:@"new_feature_share_true"] forState:UIControlStateSelected];
  135. [_sharedButton sizeToFit];
  136. [_sharedButton addTarget:self action:@selector(clickSharedButton) forControlEvents:UIControlEventTouchUpInside];
  137. }
  138. return _sharedButton;
  139. }
  140. - (NSArray *)imagesArr {
  141. return @[@"new_feature_0", @"new_feature_1", @"new_feature_2", @"new_feature_3"];
  142. }
  143. @end