123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199 |
- //
- // GuideViewController.m
- // FirstLink
- //
- // Created by unicode on 14-9-28.
- // Copyright (c) 2014年 FirstLink. All rights reserved.
- //
- #import "GuideViewController.h"
- #import "FKGuideManager.h"
- #import "FKRecommendPageController.h"
- #import "FLControllerHelper.h"
- #import "FKAppearanceUtil.h"
- #define PAGE_COUNT 4
- @interface GuideViewController ()
- <UIScrollViewDelegate>
- @property (nonatomic, strong) UIButton *doneButton;
- @property (nonatomic, strong) UIButton *closeButton;
- @property (nonatomic, strong) UIPageControl *pageControl;
- @property (nonatomic, strong) UIScrollView *pageScrollView;
- @end
- @implementation GuideViewController
- - (void)viewDidLoad {
- [super viewDidLoad];
- // Do any additional setup after loading the view.
-
- self.navigationController.navigationBarHidden = YES;
- self.tabBarController.tabBar.hidden = YES;
-
- self.edgesForExtendedLayout = UIRectEdgeAll;
-
- [self addAllSubviews];
- }
- - (void)didReceiveMemoryWarning {
- [super didReceiveMemoryWarning];
- // Dispose of any resources that can be recreated.
- }
- - (void)viewWillAppear:(BOOL)animated {
- [super viewWillAppear:animated];
-
- self.pageControl.hidden = YES;
- [self configScrollView];
- }
- /*
- #pragma mark - Navigation
- // In a storyboard-based application, you will often want to do a little preparation before navigation
- - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
- // Get the new view controller using [segue destinationViewController].
- // Pass the selected object to the new view controller.
- }
- */
- - (void)addAllSubviews {
- [self.view addSubview:self.pageScrollView];
- [self.pageScrollView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.right.bottom.top.equalTo(self.view).offset(0);
- }];
-
- [self.view addSubview:self.doneButton];
- [self.doneButton mas_makeConstraints:^(MASConstraintMaker *make) {
- make.right.equalTo(self.view).offset(-12);
- make.top.equalTo(self.view).offset(IS_IPHONE_X ? 48 : 24);
- make.height.mas_equalTo(44);
- make.width.mas_equalTo(44);
- }];
-
- [self.view addSubview:self.pageControl];
- [self.pageControl mas_makeConstraints:^(MASConstraintMaker *make) {
- make.centerX.equalTo(self.view).offset(0);
- make.bottom.equalTo(self.view).offset(IS_IPHONE_X ? -30 : 4);
- }];
-
- [self.view addSubview:self.closeButton];
- [self.closeButton mas_makeConstraints:^(MASConstraintMaker *make) {
- make.centerX.equalTo(self.view);
- make.bottom.equalTo(self.view).offset(IS_IPHONE_X ? -84 : -20);
- make.height.mas_equalTo(160);
- make.width.mas_equalTo(300);
- }];
- }
- #pragma mark - ScrollView Delegate
- - (void)scrollViewDidScroll:(UIScrollView *)scrollView {
- NSInteger curPageIndex = scrollView.contentOffset.x/UISCREENWIDTH;
- self.pageControl.currentPage = curPageIndex;
-
- if (curPageIndex == (PAGE_COUNT - 1)) {
- self.doneButton.hidden = YES;
- self.closeButton.hidden = NO;
- } else {
- self.doneButton.hidden = NO;
- self.closeButton.hidden = YES;
- }
- }
- #pragma mark - Action
- - (IBAction)clickDoneAction:(id)sender {
- [self closeGuidePage];
- }
- - (void)closeGuidePage {
- [FKGuideManager successShowOnceGuide];
- [SystemUtil saveApplicationVersion];
- [self dismissViewControllerAnimated:YES completion:^{
- }];
- }
- - (void)configScrollView {
- UIImageView *imageView;
- self.pageScrollView.contentSize = CGSizeMake(UISCREENWIDTH*PAGE_COUNT, UISCREENHEIGH);
-
- for (int index = 0; index < PAGE_COUNT; index++) {
- imageView = [[UIImageView alloc] init];
- if (IS_IPHONE_4) {
- imageView.image = [UIImage imageNamed:[NSString stringWithFormat:@"guide_iphone4_%d.jpg", index]];
- } else if (IS_IPHONE_X) {
- imageView.image = [UIImage imageNamed:[NSString stringWithFormat:@"guide_iphone_x_%d.jpg", index]];
- } else {
- imageView.image = [UIImage imageNamed:[NSString stringWithFormat:@"guide_other_%d.jpg", index]];
- }
- imageView.frame = CGRectMake(UISCREENWIDTH * index, 0 ,UISCREENWIDTH, UISCREENHEIGH);
- imageView.contentMode = UIViewContentModeScaleAspectFit;
- [self.pageScrollView addSubview:imageView];
- }
- }
- #pragma mark - Property
- - (UIButton*)doneButton {
- if (!_doneButton) {
- _doneButton = [UIButton buttonWithType:UIButtonTypeCustom];
- [_doneButton setTitle:@"跳过" forState:UIControlStateNormal];
- [_doneButton.titleLabel setFont:[UIFont systemFontOfSize:14]];
- [_doneButton setTitleColor:UIColorFromRGB(0x333333) forState:UIControlStateNormal];
- [_doneButton addTarget:self action:@selector(clickDoneAction:) forControlEvents:UIControlEventTouchUpInside];
-
- _doneButton.backgroundColor = [UIColor colorWithRed:245.0/255.0 green:239.0/255.0 blue:233.0/255.0 alpha:0.8];
- _doneButton.layer.cornerRadius = 22;
- }
- return _doneButton;
- }
- - (UIButton*)closeButton {
- if (!_closeButton) {
- _closeButton = [UIButton buttonWithType:UIButtonTypeCustom];
- // [_closeButton setTitle:@"立即体验" forState:UIControlStateNormal];
- // [_closeButton.titleLabel setFont:[UIFont boldSystemFontOfSize:15]];
- // [_closeButton setTitleColor:UIColorFromRGB(0xff624a) forState:UIControlStateNormal];
- [_closeButton addTarget:self action:@selector(clickDoneAction:) forControlEvents:UIControlEventTouchUpInside];
-
- // _closeButton.layer.cornerRadius = 8;
- // _closeButton.layer.borderWidth = 1;
- // _closeButton.layer.borderColor = UIColorFromRGB(0xff624a).CGColor;
- // _closeButton.backgroundColor = UIColorFromRGB(0xcccccc);
- _closeButton.hidden = YES;
- }
- return _closeButton;
- }
- - (UIPageControl*)pageControl {
- if (!_pageControl) {
- _pageControl = [UIPageControl new];
- _pageControl.currentPage = 0;
- _pageControl.enabled = YES;
- _pageControl.numberOfPages = PAGE_COUNT;
- _pageControl.pageIndicatorTintColor = UIColorFromRGB(0xeeeeee);
- _pageControl.currentPageIndicatorTintColor = UIColorFromRGB(0xff6362);
- }
- return _pageControl;
- }
- - (UIScrollView*)pageScrollView {
- if (!_pageScrollView) {
- _pageScrollView = [[UIScrollView alloc] init];
- _pageScrollView.pagingEnabled = YES;
- _pageScrollView.showsHorizontalScrollIndicator = NO;
- _pageScrollView.showsVerticalScrollIndicator = NO;
- _pageScrollView.delegate = self;
- }
- return _pageScrollView;
- }
- @end
|