-
Notifications
You must be signed in to change notification settings - Fork 0
/
VRGaidePangeViewControl.m
129 lines (95 loc) · 4.09 KB
/
VRGaidePangeViewControl.m
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
125
126
127
128
129
//
// VRGaidePangeViewControl.m
// VR
//
// Created by Galen on 15/8/14.
// Copyright (c) 2015年 XW. All rights reserved.
//
#import "VRGaidePangeViewControl.h"
#import "GCAutoScrollImageView.h"
#import "Define.h"
#import "Const.h"
#import "UIView+Extension.h"
#import "UIButton+WF.h"
#import "UIStoryboard+WF.h"
@interface VRGaidePangeViewControl ()<UIScrollViewDelegate>
@property (nonatomic, strong) GCAutoScrollImageView *gaidePageView;
@property (nonatomic, strong) UIScrollView *guideScrollView;
@property (nonatomic, strong) UIPageControl *pageControl;
@property (nonatomic, strong) NSMutableArray *images;
@end
@implementation VRGaidePangeViewControl
-(UIScrollView *)guideScrollView {
if (!_guideScrollView) {
_guideScrollView = [[UIScrollView alloc]initWithFrame:self.view.bounds];
_pageControl = [[UIPageControl alloc]initWithFrame:CGRectMake(self.view.frame.size.width/2-20,self.view.frame.size.height - 20,40,20)];
_images =[NSMutableArray arrayWithObjects:[UIImage imageNamed:@"1.jpg"],[UIImage imageNamed:@"2.jpg"],[UIImage imageNamed:@"3.jpg"],[UIImage imageNamed:@"4.jpg"],nil];
[self.view addSubview:_guideScrollView];
[self.view addSubview:_pageControl];
// [self setupPage];
CLog(@"%f",_guideScrollView.width);
}
return _guideScrollView;
}
- (void)awakeFromNib {
}
- (void)setupPage {
self.guideScrollView.delegate = self;
_guideScrollView.backgroundColor = [UIColor blueColor];
_guideScrollView.canCancelContentTouches = NO;
_guideScrollView.indicatorStyle = UIScrollViewIndicatorStyleWhite;
_guideScrollView.clipsToBounds = NO;
_guideScrollView.scrollEnabled = YES;
_guideScrollView.pagingEnabled = YES;
_guideScrollView.directionalLockEnabled = NO;
_guideScrollView.showsVerticalScrollIndicator = NO;
_guideScrollView.showsHorizontalScrollIndicator = NO;
NSUInteger pages = 0;
int originX = 0;
for (UIImage *image in _images) {
UIImageView *pImageView = [[UIImageView alloc]initWithFrame:CGRectZero];
pImageView.backgroundColor = [UIColor colorWithRed:0.6 green:0.6 blue:0.6 alpha:1.0];
[pImageView setImage:image];
CGRect rect = self.guideScrollView.frame;
rect.origin.x = originX;
rect.origin.y = 0;
rect.size.height = _guideScrollView.frame.size.height;
rect.size.width = _guideScrollView.frame.size.width;
pImageView.frame = rect;
pImageView.contentMode = UIViewContentModeScaleToFill;
if (pages == _images.count-1) {
UIButton *btn = [UIButton createButtonWithFrame:CGRectMake(originX, 0, _guideScrollView.width, _guideScrollView.height) Title:@"点击me" Target:self Selector:@selector(goMainStoryBoard)];
[_guideScrollView addSubview:btn];
CLog(@"width__%f_____height__%f",btn.x,btn.width);
}
[_guideScrollView addSubview:pImageView];
originX += _guideScrollView.frame.size.width;
pages ++;
}
[_pageControl addTarget:self action:@selector(changePage:) forControlEvents:UIControlEventEditingChanged];
_pageControl.numberOfPages = pages;
_pageControl.currentPage = 0;
_pageControl.tag = 110;
[_guideScrollView setContentSize:CGSizeMake(originX, _guideScrollView.frame.size.height)];
}
- (void)changePage:(id)sender {
CLog(@"指示器当前界面:%li",(long)self.pageControl.currentPage);
CGRect rect = _guideScrollView.frame;
rect.origin.x = _pageControl.currentPage * _guideScrollView.frame.size.width;
rect.origin.y = 0;
[_guideScrollView scrollRectToVisible:rect animated:YES];
}
- (void)goMainStoryBoard {
[UIStoryboard showInitialVCWithName:@"Main"];
}
#pragma mark - scrollview delegate
-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
CGFloat pageWidth = scrollView.frame.size.width;
int page = floor((scrollView.contentOffset.x - pageWidth/2)/pageWidth)+1;
self.pageControl.currentPage = page;
}
- (void)viewDidLoad {
[super viewDidLoad];
[self setupPage];
}
@end