//
// LYFeatureLoopVC.m
// Fastapp
//
// Created by wofu on 2017/11/9.
// Copyright © 2017年 wofu. All rights reserved.
//新特性
#import "LYFeatureLoopVC.h"
#import "Header.h"
#define GUIDELOOPCOUNT 3
@interface LYFeatureLoopVC ()<UIScrollViewDelegate>
@property(nonatomic,strong)NSArray *loopImageArr;
@property(nonatomic,strong)UIScrollView *scroll;
@property(nonatomic,strong)UIPageControl *pageControl;
@end
@implementation LYFeatureLoopVC
-(NSArray *)loopImageArr{
if(nil==_loopImageArr){
_loopImageArr=@[@"myzd",@"OneXivnav",@"myzd"];
}
return_loopImageArr;
}
- (void)viewDidLoad {
[superviewDidLoad];
UIScrollView *scroll=[[UIScrollViewalloc]initWithFrame:self.view.frame];
self.scroll=scroll;
scroll.delegate=self;
scroll.contentSize=CGSizeMake(GUIDELOOPCOUNT*WIDTH,HEIGHT);
scroll.showsHorizontalScrollIndicator=NO;
scroll.pagingEnabled=YES;
[self.viewaddSubview:scroll];
for (int i=0; i<GUIDELOOPCOUNT; i++) {
UIImageView *imagV=[[UIImageViewalloc]initWithFrame:CGRectMake(i*WIDTH,0, WIDTH, HEIGHT)];
imagV.image=[UIImageimageNamed:self.loopImageArr[i]];
[scroll addSubview:imagV];
}
UIPageControl *pagecontrol=[[UIPageControlalloc]initWithFrame:CGRectMake(WIDTH/2-50,HEIGHT-130,100, 50)];
self.pageControl=pagecontrol;
[self.viewaddSubview:pagecontrol];//要加到View上,不要加到scrollview上
// 设置总共有几个点
pagecontrol.numberOfPages =GUIDELOOPCOUNT;
// 设置指示器的颜色
// 非当前的指示器
pagecontrol.pageIndicatorTintColor = [UIColorgrayColor];
// 设置当前指示器的颜色
pagecontrol.currentPageIndicatorTintColor = [UIColorredColor];
// 设置当前在第几个点 , 取值范围是 0 .. (numberOfPages - 1)
// 设置的currentPage如果超出最大的范围,就在最后一个显示(numberOfPages - 1)
// 设置的currentPage如果超出最小的范围就在第一个显示0
pagecontrol.currentPage =0;
//------添加一个按钮
UIButton *enterBtn=[[UIButtonalloc]initWithFrame:CGRectMake(WIDTH-100,50, 90, 50)];
[enterBtn setTitle:@"进入"forState:UIControlStateNormal];
enterBtn.layer.cornerRadius=5;
enterBtn.layer.borderColor=[UIColorgrayColor].CGColor;
enterBtn.layer.borderWidth=1;
[self.viewaddSubview:enterBtn];
[enterBtn addTarget:selfaction:@selector(enterBtnClick)forControlEvents:UIControlEventTouchUpInside];
}
//进入应用
-(void)enterBtnClick{
}
//变更指示的点
-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
self.pageControl.currentPage = scrollView.contentOffset.x / WIDTH;
}
//新特性设计思路一:创建轮播控制器,根据当前版本和线上版本对比
// //***************加上新特性
// // app版本当前版本
// NSDictionary * infoDictionary=[[NSBundle mainBundle] infoDictionary];
// NSString *app_Version = [infoDictionary objectForKey:@"CFBundleShortVersionString"];
// NSLog(@"app当前版本----%@",app_Version);
//
// NSString *appStoreVersion=@"1.0.0";
// Reachability *reach = [Reachability reachabilityForInternetConnection];
//if([reach isReachable]){//网络可用才查询APPstore版本
// appStoreVersion=[self getAPPstoreInfo];
// [LYCommanManager sharedManager].appstoreVersion=appStoreVersion;
// if([appStoreVersion compare:app_Version] ==NSOrderedDescending ){
//
// //有新版本就提示引导页
// LYGuideloopVC *guideloopvc=[[LYGuideloopVC alloc]init];
// self.window.rootViewController=guideloopvc;
// }else {
//
// SPLoginViewController *loginVC=[[SPLoginViewController alloc]init];
// UINavigationController *loginnav=[[UINavigationController alloc]initWithRootViewController:loginVC];
// self.window.rootViewController=loginnav;
//
// }
//}else{
// SPLoginViewController *loginVC=[[SPLoginViewController alloc]init];
// UINavigationController *loginnav=[[UINavigationController alloc]initWithRootViewController:loginVC];
// self.window.rootViewController=loginnav;
// }
//获取App Store版本
//-(NSString *)getAPPstoreInfo{
//
// NSString *appID=@"1260861998";//appID---id=1077712062。。。。1260861998
// NSString *urlStr=[NSString stringWithFormat:@"https://itunes.apple.com/cn/lookup?id=%@",appID];
// 方法一
[LYWofubaoHttpRequest AppStorInforequestWithUrl:url params:nil successBlock:^(NSURLSessionDataTask *task, id responseObject) {
if(responseObject){
}
} failureBlock:^(NSURLSessionDataTask *task, NSError *error) {
}];
//
//方法二
// NSURL *url=[NSURL URLWithString:urlStr];
// NSData *json = [NSData dataWithContentsOfURL:url];
//
// NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:json options:0 error:NULL];//解析json文件
// NSLog(@"version---%@",dict);
// NSArray *results = [dict objectForKey:@"results"];
//
// NSDictionary *result = [results objectAtIndex:0];
//
// NSString *versionStr = [result objectForKey:@"version"];//获得AppStore中的app的版本
// NSLog(@"--versionStr-%@__",versionStr);
//
// return versionStr?versionStr:@"0";
//
//}
//新特性设计思路二,创建轮播的View,在最后一屏上级按钮,点击按钮是View从父结view上消失,removeFromsuperview
//APPdelgategate中调用:如下
//LaunchIntroductionView *launch = [LaunchIntroductionView sharedWithImages:@[@"yindaoone",@"yindaotwo",@"yindaothree",@"yindaoone"] buttonImage:@"login" buttonFrame:CGRectMake(kScreen_width/2 - 551/4, kScreen_height - 150, 551/2, 45)];
launch.currentColor = [UIColor redColor];
launch.nomalColor = [UIColor greenColor];
//************一下是View的实现************
//#import <UIKit/UIKit.h>
//
//#define kScreen_height [[UIScreen mainScreen] bounds].size.height
//#define kScreen_width [[UIScreen mainScreen] bounds].size.width
//
//@interface LaunchIntroductionView : UIView
///**
// * 选中page的指示器颜色,默认白色
// */
//@property (nonatomic, strong) UIColor *currentColor;
///**
// * 其他状态下的指示器的颜色,默认
// */
//@property (nonatomic, strong) UIColor *nomalColor;
///**
// * 不带按钮的引导页,滑动到最后一页,再向右滑直接隐藏引导页
// *
// * @param imageNames 背景图片数组
// *
// * @return LaunchIntroductionView对象
// */
//+(instancetype)sharedWithImages:(NSArray *) imageNames;
///**
// * 带按钮的引导页
// *
// * @param imageNames 背景图片数组
// * @param buttonImageName 按钮的图片
// * @param frame 按钮的frame
// *
// * @return LaunchIntroductionView对象
// */
//+(instancetype)sharedWithImages:(NSArray *) imageNames buttonImage:(NSString *) buttonImageName buttonFrame:(CGRect ) frame;
//
///**
// 用storyboard创建的project调用此方法
//
// @param storyboardName storyboardName
// @param imageNames 图片名字数组
// @return LaunchIntroductionView对象
// */
//+ (instancetype)sharedWithStoryboardName:(NSString *)storyboardName images:(NSArray *)imageNames;
//
///**
// 用storyboard创建的project调用此方法
//
// @param storyboardName storyboardName
// @param imageNames 图片名字数组
// @param buttonImageName 按钮图片名字
// @param frame 按钮的frame
// @return LaunchIntroductionView对象
// */
//+(instancetype)sharedWithStoryboard:(NSString *)storyboardName images:(NSArray *) imageNames buttonImage:(NSString *) buttonImageName buttonFrame:(CGRect ) frame;
//
//
//@end
***********
//#import "LaunchIntroductionView.h"
//
//static NSString *const kAppVersion = @"appVersion";
//
//@interface LaunchIntroductionView ()<UIScrollViewDelegate>
//{
// UIScrollView *launchScrollView;
// UIPageControl *page;
//}
//
//@end
//
//@implementation LaunchIntroductionView
//NSArray *images;
//BOOL isScrollOut;//在最后一页再次滑动是否隐藏引导页
//CGRect enterBtnFrame;
//NSString *enterBtnImage;
//static LaunchIntroductionView *launch = nil;
//NSString *storyboard;
//
//#pragma mark - 创建对象-->>不带button
//+(instancetype)sharedWithImages:(NSArray *)imageNames{
// images = imageNames;
// isScrollOut = YES;
// launch = [[LaunchIntroductionView alloc] initWithFrame:CGRectMake(0, 0, kScreen_width, kScreen_height)];
// launch.backgroundColor = [UIColor whiteColor];
// return launch;
//}
//
//#pragma mark - 创建对象-->>带button
//+(instancetype)sharedWithImages:(NSArray *)imageNames buttonImage:(NSString *)buttonImageName buttonFrame:(CGRect)frame{
// images = imageNames;
// isScrollOut = NO;
// enterBtnFrame = frame;
// enterBtnImage = buttonImageName;
// launch = [[LaunchIntroductionView alloc] initWithFrame:CGRectMake(0, 0, kScreen_width, kScreen_height)];
// launch.backgroundColor = [UIColor whiteColor];
// return launch;
//}
//#pragma mark - 用storyboard创建的项目时调用,不带button
//+ (instancetype)sharedWithStoryboardName:(NSString *)storyboardName images:(NSArray *)imageNames {
// images = imageNames;
// storyboard = storyboardName;
// isScrollOut = YES;
// launch = [[LaunchIntroductionView alloc] initWithFrame:CGRectMake(0, 0, kScreen_width, kScreen_height)];
// launch.backgroundColor = [UIColor whiteColor];
// return launch;
//}
//#pragma mark - 用storyboard创建的项目时调用,带button
//+ (instancetype)sharedWithStoryboard:(NSString *)storyboardName images:(NSArray *)imageNames buttonImage:(NSString *)buttonImageName buttonFrame:(CGRect)frame{
// images = imageNames;
// isScrollOut = NO;
// enterBtnFrame = frame;
// storyboard = storyboardName;
// enterBtnImage = buttonImageName;
// launch = [[LaunchIntroductionView alloc] initWithFrame:CGRectMake(0, 0, kScreen_width, kScreen_height)];
// launch.backgroundColor = [UIColor whiteColor];
// return launch;
//}
//#pragma mark - 初始化
//- (instancetype)initWithFrame:(CGRect)frame
//{
// self = [super initWithFrame:frame];
// if (self) {
// [self addObserver:self forKeyPath:@"currentColor" options:NSKeyValueObservingOptionNew context:nil];
// [self addObserver:self forKeyPath:@"nomalColor" options:NSKeyValueObservingOptionNew context:nil];
// if ([self isFirstLauch]) {
// UIStoryboard *story;
// if (storyboard) {
// story = [UIStoryboard storyboardWithName:storyboard bundle:nil];
// }
// UIWindow *window = [UIApplication sharedApplication].windows.lastObject;
// if (story) {
// UIViewController * vc = story.instantiateInitialViewController;
// window.rootViewController = vc;
// [vc.view addSubview:self];
// }else {
// [YYKeyWindow addSubview:self];
// }
// [self addImages];
// }else{
// [self removeFromSuperview];
// }
// }
// return self;
//}
//#pragma mark - 判断是不是首次登录或者版本更新
//-(BOOL )isFirstLauch{
// //获取当前版本号
// NSDictionary *infoDic = [[NSBundle mainBundle] infoDictionary];
// NSString *currentAppVersion = infoDic[@"CFBundleShortVersionString"];
// //获取上次启动应用保存的appVersion
// NSString *version = [[NSUserDefaults standardUserDefaults] objectForKey:kAppVersion];
// //版本升级或首次登录
// if (version == nil || ![version isEqualToString:currentAppVersion]) {
// [[NSUserDefaults standardUserDefaults] setObject:currentAppVersion forKey:kAppVersion];
// [[NSUserDefaults standardUserDefaults] synchronize];
// return YES;
// }else{
// return NO;
// }
//}
//#pragma mark - 添加引导页图片
//-(void)addImages{
// [self createScrollView];
//}
//#pragma mark - 创建滚动视图
//-(void)createScrollView{
// launchScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, kScreen_width, kScreen_height)];
// launchScrollView.showsHorizontalScrollIndicator = NO;
// launchScrollView.bounces = NO;
// launchScrollView.pagingEnabled = YES;
// launchScrollView.delegate = self;
// launchScrollView.contentSize = CGSizeMake(kScreen_width * images.count, kScreen_height);
// [self addSubview:launchScrollView];
// for (int i = 0; i < images.count; i ++) {
// UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(i * kScreen_width, 0, kScreen_width, kScreen_height)];
// imageView.image = [UIImage imageNamed:images[i]];
// [launchScrollView addSubview:imageView];
// if (i == images.count - 1) {
// //判断要不要添加button
// if (!isScrollOut) {
// UIButton *enterButton = [[UIButton alloc] initWithFrame:CGRectMake(enterBtnFrame.origin.x, enterBtnFrame.origin.y, enterBtnFrame.size.width, enterBtnFrame.size.height)];
// // [enterButton setImage:[UIImage imageNamed:enterBtnImage] forState:UIControlStateNormal];
// enterButton.backgroundColor = RedBackColor;
// [enterButton setTitle:@"立即体验" forState:UIControlStateNormal];
// [enterButton addTarget:self action:@selector(enterBtnClick) forControlEvents:UIControlEventTouchUpInside];
// [imageView addSubview:enterButton];
// imageView.userInteractionEnabled = YES;
// }
// }
// }
// page = [[UIPageControl alloc] initWithFrame:CGRectMake(0, kScreen_height - 50, kScreen_width, 30)];
// page.numberOfPages = images.count;
// page.backgroundColor = [UIColor clearColor];
// page.currentPage = 0;
// page.defersCurrentPageDisplay = YES;
// [self addSubview:page];
//}
//#pragma mark - 进入按钮
//-(void)enterBtnClick{
// [self hideGuidView];
//}
//#pragma mark - 隐藏引导页
//-(void)hideGuidView{
// [UIView animateWithDuration:0.5 animations:^{
// self.alpha = 0;
// dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
// [self removeFromSuperview];
// });
//
// }];
//}
//#pragma mark - scrollView Delegate
//-(void)scrollViewWillBeginDragging:(UIScrollView *)scrollView{
// int cuttentIndex = (int)(scrollView.contentOffset.x + kScreen_width/2)/kScreen_width;
// if (cuttentIndex == images.count - 1) {
// if ([self isScrolltoLeft:scrollView]) {
// if (!isScrollOut) {
// return ;
// }
// [self hideGuidView];
// }
// }
//}
//-(void)scrollViewDidScroll:(UIScrollView *)scrollView{
// if (scrollView == launchScrollView) {
// int cuttentIndex = (int)(scrollView.contentOffset.x + kScreen_width/2)/kScreen_width;
// page.currentPage = cuttentIndex;
// }
//}
//#pragma mark - 判断滚动方向
//-(BOOL )isScrolltoLeft:(UIScrollView *) scrollView{
// //返回YES为向左反动,NO为右滚动
// if ([scrollView.panGestureRecognizer translationInView:scrollView.superview].x < 0) {
// return YES;
// }else{
// return NO;
// }
//}
//#pragma mark - KVO监测值的变化
//-(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSString *,id> *)change context:(void *)context{
// if ([keyPath isEqualToString:@"currentColor"]) {
// page.currentPageIndicatorTintColor = self.currentColor;
// }
// if ([keyPath isEqualToString:@"nomalColor"]) {
// page.pageIndicatorTintColor = self.nomalColor;
// }
//}
//
//@end
@end