No Description

GuideViewController.m 6.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. //
  2. // GuideViewController.m
  3. // FirstLink
  4. //
  5. // Created by unicode on 14-9-28.
  6. // Copyright (c) 2014年 FirstLink. All rights reserved.
  7. //
  8. #import "GuideViewController.h"
  9. #import "FKGuideManager.h"
  10. #import "FKRecommendPageController.h"
  11. #import "FLControllerHelper.h"
  12. #import "FKAppearanceUtil.h"
  13. #define PAGE_COUNT 4
  14. @interface GuideViewController ()
  15. <UIScrollViewDelegate>
  16. @property (nonatomic, strong) UIButton *doneButton;
  17. @property (nonatomic, strong) UIButton *closeButton;
  18. @property (nonatomic, strong) UIPageControl *pageControl;
  19. @property (nonatomic, strong) UIScrollView *pageScrollView;
  20. @end
  21. @implementation GuideViewController
  22. - (void)viewDidLoad {
  23. [super viewDidLoad];
  24. // Do any additional setup after loading the view.
  25. self.navigationController.navigationBarHidden = YES;
  26. self.tabBarController.tabBar.hidden = YES;
  27. self.edgesForExtendedLayout = UIRectEdgeAll;
  28. [self addAllSubviews];
  29. }
  30. - (void)didReceiveMemoryWarning {
  31. [super didReceiveMemoryWarning];
  32. // Dispose of any resources that can be recreated.
  33. }
  34. - (void)viewWillAppear:(BOOL)animated {
  35. [super viewWillAppear:animated];
  36. self.pageControl.hidden = YES;
  37. [self configScrollView];
  38. }
  39. /*
  40. #pragma mark - Navigation
  41. // In a storyboard-based application, you will often want to do a little preparation before navigation
  42. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  43. // Get the new view controller using [segue destinationViewController].
  44. // Pass the selected object to the new view controller.
  45. }
  46. */
  47. - (void)addAllSubviews {
  48. [self.view addSubview:self.pageScrollView];
  49. [self.pageScrollView mas_makeConstraints:^(MASConstraintMaker *make) {
  50. make.left.right.bottom.top.equalTo(self.view).offset(0);
  51. }];
  52. [self.view addSubview:self.doneButton];
  53. [self.doneButton mas_makeConstraints:^(MASConstraintMaker *make) {
  54. make.right.equalTo(self.view).offset(-12);
  55. make.top.equalTo(self.view).offset(IS_IPHONE_X ? 48 : 24);
  56. make.height.mas_equalTo(44);
  57. make.width.mas_equalTo(44);
  58. }];
  59. [self.view addSubview:self.pageControl];
  60. [self.pageControl mas_makeConstraints:^(MASConstraintMaker *make) {
  61. make.centerX.equalTo(self.view).offset(0);
  62. make.bottom.equalTo(self.view).offset(IS_IPHONE_X ? -30 : 4);
  63. }];
  64. [self.view addSubview:self.closeButton];
  65. [self.closeButton mas_makeConstraints:^(MASConstraintMaker *make) {
  66. make.centerX.equalTo(self.view);
  67. make.bottom.equalTo(self.view).offset(IS_IPHONE_X ? -84 : -20);
  68. make.height.mas_equalTo(160);
  69. make.width.mas_equalTo(300);
  70. }];
  71. }
  72. #pragma mark - ScrollView Delegate
  73. - (void)scrollViewDidScroll:(UIScrollView *)scrollView {
  74. NSInteger curPageIndex = scrollView.contentOffset.x/UISCREENWIDTH;
  75. self.pageControl.currentPage = curPageIndex;
  76. if (curPageIndex == (PAGE_COUNT - 1)) {
  77. self.doneButton.hidden = YES;
  78. self.closeButton.hidden = NO;
  79. } else {
  80. self.doneButton.hidden = NO;
  81. self.closeButton.hidden = YES;
  82. }
  83. }
  84. #pragma mark - Action
  85. - (IBAction)clickDoneAction:(id)sender {
  86. [self closeGuidePage];
  87. }
  88. - (void)closeGuidePage {
  89. [FKGuideManager successShowOnceGuide];
  90. [SystemUtil saveApplicationVersion];
  91. [self dismissViewControllerAnimated:YES completion:^{
  92. }];
  93. }
  94. - (void)configScrollView {
  95. UIImageView *imageView;
  96. self.pageScrollView.contentSize = CGSizeMake(UISCREENWIDTH*PAGE_COUNT, UISCREENHEIGH);
  97. for (int index = 0; index < PAGE_COUNT; index++) {
  98. imageView = [[UIImageView alloc] init];
  99. if (IS_IPHONE_4) {
  100. imageView.image = [UIImage imageNamed:[NSString stringWithFormat:@"guide_iphone4_%d.jpg", index]];
  101. } else if (IS_IPHONE_X) {
  102. imageView.image = [UIImage imageNamed:[NSString stringWithFormat:@"guide_iphone_x_%d.jpg", index]];
  103. } else {
  104. imageView.image = [UIImage imageNamed:[NSString stringWithFormat:@"guide_other_%d.jpg", index]];
  105. }
  106. imageView.frame = CGRectMake(UISCREENWIDTH * index, 0 ,UISCREENWIDTH, UISCREENHEIGH);
  107. imageView.contentMode = UIViewContentModeScaleAspectFit;
  108. [self.pageScrollView addSubview:imageView];
  109. }
  110. }
  111. #pragma mark - Property
  112. - (UIButton*)doneButton {
  113. if (!_doneButton) {
  114. _doneButton = [UIButton buttonWithType:UIButtonTypeCustom];
  115. [_doneButton setTitle:@"跳过" forState:UIControlStateNormal];
  116. [_doneButton.titleLabel setFont:[UIFont systemFontOfSize:14]];
  117. [_doneButton setTitleColor:UIColorFromRGB(0x333333) forState:UIControlStateNormal];
  118. [_doneButton addTarget:self action:@selector(clickDoneAction:) forControlEvents:UIControlEventTouchUpInside];
  119. _doneButton.backgroundColor = [UIColor colorWithRed:245.0/255.0 green:239.0/255.0 blue:233.0/255.0 alpha:0.8];
  120. _doneButton.layer.cornerRadius = 22;
  121. }
  122. return _doneButton;
  123. }
  124. - (UIButton*)closeButton {
  125. if (!_closeButton) {
  126. _closeButton = [UIButton buttonWithType:UIButtonTypeCustom];
  127. // [_closeButton setTitle:@"立即体验" forState:UIControlStateNormal];
  128. // [_closeButton.titleLabel setFont:[UIFont boldSystemFontOfSize:15]];
  129. // [_closeButton setTitleColor:UIColorFromRGB(0xff624a) forState:UIControlStateNormal];
  130. [_closeButton addTarget:self action:@selector(clickDoneAction:) forControlEvents:UIControlEventTouchUpInside];
  131. // _closeButton.layer.cornerRadius = 8;
  132. // _closeButton.layer.borderWidth = 1;
  133. // _closeButton.layer.borderColor = UIColorFromRGB(0xff624a).CGColor;
  134. // _closeButton.backgroundColor = UIColorFromRGB(0xcccccc);
  135. _closeButton.hidden = YES;
  136. }
  137. return _closeButton;
  138. }
  139. - (UIPageControl*)pageControl {
  140. if (!_pageControl) {
  141. _pageControl = [UIPageControl new];
  142. _pageControl.currentPage = 0;
  143. _pageControl.enabled = YES;
  144. _pageControl.numberOfPages = PAGE_COUNT;
  145. _pageControl.pageIndicatorTintColor = UIColorFromRGB(0xeeeeee);
  146. _pageControl.currentPageIndicatorTintColor = UIColorFromRGB(0xff6362);
  147. }
  148. return _pageControl;
  149. }
  150. - (UIScrollView*)pageScrollView {
  151. if (!_pageScrollView) {
  152. _pageScrollView = [[UIScrollView alloc] init];
  153. _pageScrollView.pagingEnabled = YES;
  154. _pageScrollView.showsHorizontalScrollIndicator = NO;
  155. _pageScrollView.showsVerticalScrollIndicator = NO;
  156. _pageScrollView.delegate = self;
  157. }
  158. return _pageScrollView;
  159. }
  160. @end