262 lines
8.3 KiB
Objective-C
262 lines
8.3 KiB
Objective-C
//
|
|
// MyIntroductionViewController.m
|
|
// Ifish
|
|
//
|
|
// Created by imac on 15/11/26.
|
|
// Copyright © 2015年 imac. All rights reserved.
|
|
//
|
|
|
|
#import "MyIntroductionViewController.h"
|
|
#define kGoButtonHeight 60
|
|
#define kGoButtonDefaultTitle @""
|
|
///#define kBackColor [UIColor colorWithRed:0 green:157.f/255 blue:232.f/255 alpha:1]
|
|
#define kGoButtonBackColor [UIColor colorWithRed:0 green:109.f/255 blue:205.f/255 alpha:0.48]
|
|
#import "AppDelegate.h"
|
|
#import "RegistViewController.h"
|
|
static MyIntroductionViewController * introduction = nil;
|
|
@interface MyIntroductionViewController ()<UIScrollViewDelegate>
|
|
{
|
|
|
|
NSArray * _imageNames;
|
|
NSArray * _titles;
|
|
NSArray * _contents;
|
|
NSInteger _page;
|
|
// void ((^_goActionBlock)(void));
|
|
}
|
|
@property(nonatomic,strong)NSMutableArray * imageViews;
|
|
@property(nonatomic,strong)UIScrollView * scrollView;
|
|
@property(nonatomic,strong)UIPageControl * pageControl;
|
|
@property(nonatomic,strong)UIButton * goButton;
|
|
@property(nonatomic,strong)UILabel * titleLable;
|
|
@property(nonatomic,strong)UILabel * contentLable;
|
|
@property(nonatomic,strong)UIButton*startbutton;
|
|
@end
|
|
|
|
@implementation MyIntroductionViewController
|
|
-(instancetype)init{
|
|
self = [super init];
|
|
if (self) {
|
|
[self initData];
|
|
[self configViews];
|
|
}
|
|
return self;
|
|
}
|
|
-(void)initData{
|
|
self.introductionStyle = LXIntroductionStyleAllPageGoButton;
|
|
}
|
|
-(void)configViews{
|
|
|
|
self.view.backgroundColor=COLOR_BACK_;
|
|
|
|
[self.view addSubview:self.scrollView];
|
|
|
|
[self.view addSubview:self.goButton];
|
|
|
|
}
|
|
-(void)setPage:(NSInteger)page{
|
|
_page = page;
|
|
[self setUpTitleLabel];
|
|
[self setUpContentLabel];
|
|
self.pageControl.currentPage = _page;
|
|
|
|
}
|
|
-(void)setUpTitleLabel{
|
|
self.titleLable.text = self.titles[self.page];
|
|
}
|
|
-(void)setHiddenPageControl:(BOOL)hiddenPageControl{
|
|
self.pageControl.hidden=hiddenPageControl;
|
|
}
|
|
-(void)setIntroductionStyle:(LXIntroductionStyle)introductionStyle{
|
|
switch (introductionStyle) {
|
|
case LXIntroductionStyleAllPageGoButton:
|
|
{
|
|
[self.view addSubview:self.goButton];
|
|
}
|
|
break;
|
|
case LXIntroductionStyleFullScreenGoButton:
|
|
{
|
|
UIImageView * imgV = self.imageViews.lastObject;
|
|
self.goButton.frame = CGRectMake(0, 0, self.scrollView.bounds.size.width, self.scrollView.bounds.size.height);
|
|
[self.goButton setTitle:@"" forState:UIControlStateNormal];
|
|
[imgV addSubview:self.goButton];
|
|
self.goButton.backgroundColor=[UIColor clearColor];
|
|
}
|
|
break;
|
|
case LXIntroductionStyleLastPageGoButton:
|
|
{
|
|
UIImageView * imgV = self.imageViews.lastObject;
|
|
[imgV addSubview:self.goButton];
|
|
}
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
|
|
-(void)setUpScrollView{
|
|
CGFloat width = CGRectGetWidth([UIScreen mainScreen].bounds);
|
|
CGFloat height = CGRectGetHeight([UIScreen mainScreen].bounds);
|
|
self.scrollView.contentSize = CGSizeMake(width * self.imageNames.count, height);
|
|
self.scrollView.bounces=NO;
|
|
//views
|
|
for (int i=0; i<self.imageNames.count; i++) {
|
|
UIImageView * imgV = [[UIImageView alloc]initWithImage:[UIImage imageNamed:self.imageNames[i]]];
|
|
imgV.userInteractionEnabled=true;
|
|
imgV.contentMode = UIViewContentModeScaleAspectFit;
|
|
imgV.layer.masksToBounds = YES;
|
|
CGFloat x = i * width;
|
|
imgV.frame = CGRectMake(x, 0, width, height);
|
|
[self.scrollView addSubview:imgV];
|
|
[self.imageViews addObject:imgV];
|
|
}
|
|
}
|
|
-(NSMutableArray *)imageViews{
|
|
if (!_imageViews) {
|
|
_imageViews = [NSMutableArray array];
|
|
}
|
|
return _imageViews;
|
|
}
|
|
-(NSInteger)page{
|
|
return _page;
|
|
}
|
|
-(void)setImageNames:(NSArray *)imageNames{
|
|
if (imageNames) {
|
|
_imageNames = imageNames;
|
|
[self setUpScrollView];
|
|
self.pageControl.numberOfPages = _imageNames.count;
|
|
}
|
|
}
|
|
-(void)setTitles:(NSArray *)titles{
|
|
if (titles) {
|
|
_titles =titles;
|
|
[self setUpTitleLabel];
|
|
}
|
|
}
|
|
-(NSArray *)titles{
|
|
return _titles;
|
|
}
|
|
|
|
-(void)setContents:(NSArray *)contents{
|
|
if (contents) {
|
|
_contents = contents;
|
|
[self setUpContentLabel];
|
|
}
|
|
}
|
|
-(NSArray *)contents{
|
|
return _contents;
|
|
}
|
|
-(void)setUpContentLabel{
|
|
self.contentLable.text = self.contents[self.page];
|
|
}
|
|
-(NSArray *)imageNames{
|
|
return _imageNames;
|
|
}
|
|
|
|
-(UIScrollView *)scrollView{
|
|
if (!_scrollView ) {
|
|
_scrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height)];
|
|
_scrollView.pagingEnabled=true;
|
|
_scrollView.delegate=self;
|
|
_scrollView.showsHorizontalScrollIndicator=false;
|
|
_scrollView.showsVerticalScrollIndicator=false;
|
|
}
|
|
return _scrollView;
|
|
}
|
|
-(UIButton *)goButton{
|
|
if (!_goButton) {
|
|
_goButton = [UIButton buttonWithType:UIButtonTypeCustom];
|
|
|
|
[_goButton setTitle:kGoButtonDefaultTitle forState:UIControlStateNormal];
|
|
[_goButton setTitleColor:[UIColor lightTextColor] forState:UIControlStateHighlighted];
|
|
_goButton.frame = CGRectMake(30,kScreenSize.height/2+40,kScreenSize.width-60,100);
|
|
_goButton.tintColor=[UIColor whiteColor];
|
|
|
|
[_goButton addTarget:self action:@selector(goButtonClick:) forControlEvents:UIControlEventTouchUpInside];
|
|
_goButton.backgroundColor =[UIColor clearColor];
|
|
|
|
|
|
}
|
|
return _goButton;
|
|
}
|
|
-(UILabel *)titleLable{
|
|
if (!_titleLable) {
|
|
_titleLable = [[UILabel alloc]initWithFrame:CGRectMake(0, kGoButtonHeight, self.scrollView.frame.size.width, kGoButtonHeight)];
|
|
_titleLable.textColor=[UIColor whiteColor];
|
|
_titleLable.font = [UIFont boldSystemFontOfSize:36];
|
|
_titleLable.textAlignment=NSTextAlignmentCenter;
|
|
[self.view addSubview:_titleLable];
|
|
}
|
|
return _titleLable;
|
|
}
|
|
-(UILabel *)contentLable{
|
|
if (!_contentLable) {
|
|
_contentLable = [[UILabel alloc]initWithFrame:CGRectMake(0, self.goButton.frame.origin.y-kGoButtonHeight, self.scrollView.bounds.size.width, kGoButtonHeight)];
|
|
_contentLable.textColor=[UIColor whiteColor];
|
|
_contentLable.font = [UIFont boldSystemFontOfSize:16];
|
|
_contentLable.textAlignment=NSTextAlignmentCenter;
|
|
[self.view addSubview:_contentLable];
|
|
|
|
}
|
|
return _contentLable;
|
|
}
|
|
-(UIPageControl *)pageControl{
|
|
if (!_pageControl) {
|
|
_pageControl = [[UIPageControl alloc]initWithFrame:CGRectMake(0, kGoButtonHeight, self.view.bounds.size.width, kGoButtonHeight)];
|
|
_pageControl.currentPage = 0;
|
|
[self.view addSubview:_pageControl];
|
|
}
|
|
return _pageControl;
|
|
}
|
|
-(void)goButtonClick:(id)sender{
|
|
if (self.goActionCallBack) {
|
|
self.goActionCallBack(self);
|
|
}
|
|
}
|
|
-(void)goButtonActionBlock:(void (^)(void))goButtonActionBlock{
|
|
self.goActionCallBack = nil;
|
|
self.goActionCallBack = [goButtonActionBlock copy];
|
|
}
|
|
|
|
//MARK: - scrollView delegate
|
|
//结束滚动
|
|
-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
|
|
[self dismissLabel];
|
|
}
|
|
|
|
//MARK: - 动画部分
|
|
-(void)dismissLabel{
|
|
|
|
[UIView animateWithDuration:0.25 delay:0 options:UIViewAnimationOptionCurveEaseIn animations:^{
|
|
self.titleLable.alpha=0;
|
|
self.contentLable.alpha=0;
|
|
} completion:^(BOOL finished) {
|
|
[self showLabel];
|
|
self.page = self.scrollView.contentOffset.x / self.scrollView.bounds.size.width;
|
|
}];
|
|
}
|
|
-(void)showLabel{
|
|
[UIView animateWithDuration:0.25 delay:0 options:UIViewAnimationOptionCurveEaseIn animations:^{
|
|
self.titleLable.alpha=1;
|
|
self.contentLable.alpha=1;
|
|
} completion:^(BOOL finished) {
|
|
|
|
}];
|
|
}
|
|
+(MyIntroductionViewController *)shareIntrduction{
|
|
if (!introduction) {
|
|
introduction= [[MyIntroductionViewController alloc]init];
|
|
}
|
|
return introduction;
|
|
}
|
|
|
|
+(instancetype)showIntroductionWithTitles:(NSArray *)titles contents:(NSArray *)contents imageNames:(NSArray *)imageNames style:(LXIntroductionStyle)introductionStyle goButtonActionBlock:(GoActionBack)goButtonActionBlock{
|
|
MyIntroductionViewController * intrVC = [MyIntroductionViewController shareIntrduction];
|
|
intrVC.titles = titles;
|
|
intrVC.contents = contents;
|
|
intrVC.imageNames = imageNames;
|
|
intrVC.introductionStyle = introductionStyle;
|
|
intrVC.goActionCallBack = goButtonActionBlock;
|
|
return intrVC;
|
|
}
|
|
@end
|