YH_GuideViewController.m
3.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
//
// YH_GuideViewController.m
// YH_Mall
//
// Created by YOHO on 15/4/30.
// Copyright (c) 2015年 YOHO. All rights reserved.
//
#import "YH_GuideViewController.h"
#import "SMPageControl.h"
#define kNumberOfImages 4
@interface YH_GuideViewController ()<UIScrollViewDelegate>
@property (strong ,nonatomic) UIScrollView *scrollView;
@property (strong ,nonatomic) SMPageControl *pageControl;
@property (assign ,nonatomic) NSInteger currentPage;
@property (strong ,nonatomic) UIButton *enterButton;
@end
@implementation YH_GuideViewController
- (instancetype)init
{
self = [super init];
if(self){
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
self.enterButton = [UIButton buttonWithType:UIButtonTypeCustom];
self.enterButton.backgroundColor = [UIColor clearColor];
[self.enterButton addTarget:self action:@selector(didClickEnterButton:) forControlEvents:UIControlEventTouchUpInside];
}
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
[self.view addSubview:self.scrollView];
[self.view insertSubview:self.pageControl aboveSubview:self.scrollView];
}
- (UIScrollView *)scrollView
{
if(!_scrollView){
_scrollView = [[UIScrollView alloc] initWithFrame:self.view.bounds];
[_scrollView setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight];
_scrollView.contentSize = CGSizeMake(kScreenWidth * kNumberOfImages, CGRectGetHeight(self.view.frame));
_scrollView.pagingEnabled = YES;
_scrollView.delegate = self;
_scrollView.showsHorizontalScrollIndicator = NO;
_scrollView.showsVerticalScrollIndicator = NO;
_scrollView.bounces = NO;
for (int i = 0; i < kNumberOfImages; i++) {
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(i * kScreenWidth , 0, kScreenWidth, kScreenHeight)];
NSString *imageName = [NSString stringWithFormat:@"guide_%d.png",(i + 1)];
imageView.image = [UIImage imageNamed:imageName];
if(i == kNumberOfImages - 1){
imageView.userInteractionEnabled = YES;
CGSize size = CGSizeMake(124*kScreenPoint6Scale, 45*kScreenPoint6Scale);
if(Screen35in){
self.enterButton.frame = CGRectMake((kScreenWidth - size.width) / 2.0f, 386, size.width, size.height);
} else{
self.enterButton.frame = CGRectMake((kScreenWidth - size.width) / 2.0f, 538*kScreenPoint6Scale, size.width, size.height);
}
[imageView addSubview:self.enterButton];
}
[self.scrollView addSubview:imageView];
}
}
return _scrollView;
}
- (SMPageControl *)pageControl
{
if(!_pageControl){
_pageControl = [[SMPageControl alloc] init];
_pageControl.indicatorMargin = 18.0f;
_pageControl.numberOfPages = kNumberOfImages;
_pageControl.userInteractionEnabled = NO;
[_pageControl sizeToFit];
_pageControl.center = self.enterButton.center;
CGRect frame = _pageControl.frame;
if(Screen35in){
frame.origin.y += 0.8 * CGRectGetHeight(self.enterButton.frame);
} else if(Screen40in){
frame.origin.y += CGRectGetHeight(self.enterButton.frame);
} else{
frame.origin.y += 1.3 * CGRectGetHeight(self.enterButton.frame);
}
_pageControl.frame = frame;
}
return _pageControl;
}
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
NSInteger page = scrollView.contentOffset.x / kScreenWidth;
if(page != self.currentPage){
self.currentPage = page;
}
self.pageControl.currentPage = self.currentPage;
}
- (void)didClickEnterButton:(UIButton *)button
{
if(self.block){
self.block();
}
}
- (BOOL)prefersStatusBarHidden
{
return YES;
}
@end