GuideViewController.h
#import <UIKit/UIKit.h>
@interface GuideViewController : UIViewController<UIScrollViewDelegate>
@property (nonatomic) UIScrollView *scrollView;
@property (nonatomic) NSArray *array;//保存图片名
@end
GuideViewController.m
#import "GuideViewController.h"
#define HEIGHT [UIScreen mainScreen].bounds.size.height
#define WIDTH [UIScreen mainScreen].bounds.size.width
@interface GuideViewController ()
@end
@implementation GuideViewController
- (void)viewDidLoad {
[super viewDidLoad];
_scrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
_scrollView.backgroundColor = [UIColor groupTableViewBackgroundColor];
[self.view addSubview: _scrollView];
//修复ScrollerView偏移(下移)
self.automaticallyAdjustsScrollViewInsets = NO;
//设置是否有橡皮筋效果属性
self.scrollView.bounces = YES;
//设置是否使用分页属性
_scrollView.pagingEnabled = YES;
//设置是否允许滚动属性
_scrollView.scrollEnabled = YES;
//设置是否显示水平、竖直滚动条属性
_scrollView.showsHorizontalScrollIndicator = YES;
_scrollView.showsVerticalScrollIndicator = YES;
_scrollView.userInteractionEnabled = YES;
if (HEIGHT == 480) {
_array = [NSArray arrayWithObjects:[UIImage imageNamed:@"引导页1-640-960.png.png"],[UIImage imageNamed:@"引导页2-640-960.png.png"],[UIImage imageNamed:@"引导页3-640-960.png.png"], nil];
} else if (HEIGHT == 568){
_array = [NSArray arrayWithObjects:[UIImage imageNamed:@"引导页1-720-1280.png"],[UIImage imageNamed:@"引导页2-720-1280.png"],[UIImage imageNamed:@"引导页3-720-1280.png"], nil];
}else if (HEIGHT == 667){
_array = [NSArray arrayWithObjects:[UIImage imageNamed:@"引导页1-720-1280.png"],[UIImage imageNamed:@"引导页2-720-1280.png"],[UIImage imageNamed:@"引导页3-720-1280.png"], nil];
}else if (HEIGHT == 736){
_array = [NSArray arrayWithObjects:[UIImage imageNamed:@"引导页1-1080-1920.png"],[UIImage imageNamed:@"引导页2-1080-1920.png"],[UIImage imageNamed:@"引导页3-1080-1920.png"], nil];
}
for (int i=0; i<[_array count]; i++) {
UIImageView *view = [[UIImageView alloc]initWithFrame:CGRectMake(i*_scrollView.frame.size.width, 0, _scrollView.frame.size.width, _scrollView.frame.size.height)];
view.userInteractionEnabled = YES;
if (i == _array.count-1) {
_button = [UIButton buttonWithType:UIButtonTypeSystem];
if (HEIGHT == 480) {
_button.frame = CGRectMake((WIDTH-130)/2, 115, 130, 40);
} else if (HEIGHT == 568){
_button.frame = CGRectMake((WIDTH-150)/2, 137, 150, 40);
}else if (HEIGHT == 667){
_button.frame = CGRectMake((WIDTH-160)/2, 158, 160, 50);
}else if (HEIGHT == 736){
_button.frame = CGRectMake((WIDTH-200)/2, 176, 200, 60);
}
[_button setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
[_button setBackgroundColor:[UIColor clearColor]];
[_button addTarget:self action:@selector(startClick:) forControlEvents:UIControlEventTouchUpInside];
[view addSubview:_button];
}
view.image = _array[i];
[_scrollView addSubview:view];
}
//设置内容范围属性
_scrollView.contentSize = CGSizeMake([_array count]*self.view.frame.size.width, self.view.frame.size.height);
}
#pragma scrollViewDelegate
-(void)scrollViewDidScroll:(UIScrollView *)scrollView{
NSLog(@"完成滚动!!");
}
-(void)scrollViewWillBeginDragging:(UIScrollView *)scrollView{
NSLog(@"将要开始拖动!!");
}
-(void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate{
NSLog(@"结束拖动!!");
}
-(void)scrollViewWillBeginDecelerating:(UIScrollView *)scrollView{
NSLog(@"滚动将要开始减速!!");
}
-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
NSLog(@"滚动减速到停止!!");
}
-(BOOL)scrollViewShouldScrollToTop:(UIScrollView *)scrollView{
NSLog(@"是否滚动到顶部??");
return YES;
}
-(void)scrollViewDidScrollToTop:(UIScrollView *)scrollView{
NSLog(@"滚动到顶部!!");
}
@end