// AppDelegate.m
倒入头文件
//轮播图
#import "stareViewController.h"
//直接跳入标签控制器
#import "ViewController.h"
=========括号内
//判断是不是第一次打开 如果不是就不显示
//判断是否是第一次不是就没有启动动画
BOOL show=[[NSUserDefaults standardUserDefaults] objectForKey:@"show"];
if(show==NO)
{
[[NSUserDefaults standardUserDefaults]setBool:YES forKey:@"show"];
stareViewController *st=[stareViewController new];
self.window.rootViewController=st;
}
else
{
ViewController *vc = [[ViewController alloc] init];
self.window.rootViewController = vc;
}
=======括号外
// ViewController.m 继承 UITabBarController
//标签控制器的头文件
#import "OneViewController.h"
#import "fenLeiViewController.h"
#import "goouWuViewController.h"
#import "GoeuViewController.h"
OneViewController *one = [[OneViewController alloc]init];
fenLeiViewController *fenLei = [[fenLeiViewController alloc] init];
goouWuViewController *gouWuChe = [[goouWuViewController alloc]init];
GoeuViewController *myKuaiF = [[GoeuViewController alloc]init];
UINavigationController *navo = [[UINavigationController alloc]initWithRootViewController:one];
UINavigationController *navf = [[UINavigationController alloc]initWithRootViewController:fenLei];
UINavigationController *navg = [[UINavigationController alloc]initWithRootViewController:gouWuChe];
UINavigationController *navm = [[UINavigationController alloc]initWithRootViewController:myKuaiF];
UITabBarItem *item1 = [[UITabBarItem alloc]initWithTitle:@"首页" image:[UIImage imageNamed:@"2.png"] tag:1];
UITabBarItem *item2 = [[UITabBarItem alloc]initWithTitle:@"分类" image:[UIImage imageNamed:@"分类.png"] tag:1];
UITabBarItem *item3 = [[UITabBarItem alloc]initWithTitle:@"购物车" image:[UIImage imageNamed:@"3.png"] tag:1];
UITabBarItem *item4 = [[UITabBarItem alloc]initWithTitle:@"我的快方" image:[UIImage imageNamed:@"4.png"] tag:1];
navo.tabBarItem = item1;
navf.tabBarItem = item2;
navg.tabBarItem = item3;
navm.tabBarItem = item4;
self.viewControllers = @[navo,navf,navg,myKuaiF];
// stareViewController.m
倒入头文件
#import "OneViewController.h"
#import "ViewController.h"
{
//创建滑动控件
UIScrollView *theScroll;
//分页控件
UIPageControl *thePage;
//创建整型类
NSInteger tegPageTime;
//创建数组;
NSArray *theArray;
//计数器
NSTimer *theTime;
}
///=================================括号内
//获取屏幕的宽
float width = self.view.frame.size.width;
//获取屏幕的高
float height = self.view.frame.size.height;
//代替 初始化滚动控件
theScroll = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, width, height)];
//获取屏幕X轴
float X = 0.0;
//一共四张图片
for (int i = 0; i < 4; i++)
{
//图片初始化
UIImageView *theImg = [[UIImageView alloc] initWithFrame:CGRectMake(X, 0, width, height)];
//将图片添加到视图里
theArray = @[[UIImage imageNamed:@"q1"],[UIImage imageNamed:@"q2"],[UIImage imageNamed:@"q3"],[UIImage imageNamed:@"q4"],];
//将图片与数组下标绑定
theImg.image = theArray[i];
//将图片添加到滚动视图中
[theScroll addSubview:theImg];
//设置滚动视图的坐标 原代码
//(width=self.view.frame.size.width+self.view.frame.size.width+self.view.frame.size.width+self.view.frame.size.width,)
X += width;
}
//设置滚动视图的大小
theScroll.contentSize = CGSizeMake(width * 4, height);
// 设置滚动视图按页滚动
theScroll.pagingEnabled = YES;
//滚动条隐藏
theScroll.showsHorizontalScrollIndicator = NO;
//设置代理
theScroll.delegate = self;
//初始化页码
thePage = [[UIPageControl alloc]initWithFrame:CGRectMake(width /2-50, 570, 100, 30)];
//页数
thePage.numberOfPages = 4;
//初始页第一页
thePage.currentPage = 0;
//清除原来颜色
thePage.backgroundColor = [UIColor clearColor];
//没动原来
thePage.pageIndicatorTintColor = [UIColor greenColor];
//当前翻页显示的颜色
thePage.currentPageIndicatorTintColor = [UIColor redColor];
//顺序不能乱
[self.view addSubview:theScroll];
[self.view addSubview:thePage];
//记录当前图片
tegPageTime = thePage.currentPage;
//第一个几秒钟换一下 事件
theTime = [NSTimer scheduledTimerWithTimeInterval:3 target:self selector:@selector(scroll) userInfo:nil repeats:YES];
//=========括号外=============
//事件
-(void)scroll
{
tegPageTime ++;
if (tegPageTime>=theArray.count)
{
tegPageTime = 0;
}
[theScroll setContentOffset:CGPointMake(tegPageTime*theScroll.frame.size.width, 0) animated:YES];
}
//表示在滑动滚动视图的时候调用此方法
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
CGPoint point=scrollView.contentOffset;//偏移
//获得所在位置
thePage.currentPage=point.x / scrollView.frame.size.width;
UIButton *theBtn = [[UIButton alloc]init];
if (thePage.currentPage == 3)
{
//停止图片滚动
[theTime setFireDate:[NSDate distantFuture]];
theBtn.frame = CGRectMake(133, 653, 150, 50);
theBtn.backgroundColor = [UIColor orangeColor];
theBtn.layer.cornerRadius = 26;
[theBtn setTitle:@"立即登录" forState:UIControlStateNormal];
//添加按钮触发事件:必须要用(UIControlEventTouchUpInside)
[theBtn addTarget:self action:@selector(TiaoZh) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:theBtn];
//设置与用户无法交互(这样即可解决按钮在前面的那页中显示)
// scrollView.userInteractionEnabled = NO;
}
}
//实现页码和滚动视图的关联
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollVie
{
thePage.currentPage = theScroll.contentOffset.x / self.view.frame.size.width;
}
//跳转
-(void)TiaoZh
{
ViewController *VC = [[ViewController alloc]init];
[self presentViewController:VC animated:YES completion:nil];
}