效果图如上,实现的是一个页面引导页,最后跳到主页面,主页面是一个navigationController,但是导航栏给我隐藏了。

文件目录:自己定制的viewcontroller以及navigationController

先贴代码吧。

1、首先是GuideViewController类

GuideViewController.h

#import <UIKit/UIKit.h>
#import "JKViewController.h" @interface GuideViewController : JKViewController <UIScrollViewDelegate> @property (strong,nonatomic) UIScrollView *scrollView;
@property (strong,nonatomic) NSMutableArray *slideImages;
@property (strong,nonatomic) UIPageControl *pageControl; @end

GuideViewController.m

#import "GuideViewController.h"
#import "JKNavigationController.h" @interface GuideViewController()
{
NSTimer *fanyeTime;
} @end @implementation GuideViewController @synthesize slideImages,scrollView;
@synthesize pageControl; -(void)dealloc
{
[fanyeTime release];
[scrollView release];
[slideImages release];
[pageControl release];
} -(void)viewDidLoad
{
[super viewDidLoad];
//定时器循环
fanyeTime = [NSTimer scheduledTimerWithTimeInterval: target:self selector:@selector(runTimePage) userInfo:nil repeats:YES];
//初始化 scrollView
self.scrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(, , , self.view.frame.size.height)];
scrollView.bounces = YES;
scrollView.pagingEnabled = YES;
scrollView.delegate = self;
scrollView.showsHorizontalScrollIndicator = NO;
[self.view addSubview:scrollView]; //初始化数组,并添加四张照片
slideImages = [[NSMutableArray alloc]initWithObjects:@"26.jpg",@"27.jpg",@"28.jpg",@"29.jpg",@" ",nil];
//初始化pageControl
self.pageControl = [[UIPageControl alloc]initWithFrame:CGRectMake(,,,)];
[pageControl setCurrentPageIndicatorTintColor:[UIColor redColor]];
[pageControl setPageIndicatorTintColor:[UIColor blackColor]];
pageControl.numberOfPages = [self.slideImages count] - ;
pageControl.currentPage = ;
[pageControl addTarget:self action:@selector(turnPage) forControlEvents:UIControlEventValueChanged];
[self.view addSubview:pageControl]; //创建四个图片 imageView
for (int i = ; i < [slideImages count]; i++) {
UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:[slideImages objectAtIndex:i]]]; imageView.frame = CGRectMake( * i, , , self.view.frame.size.height); [scrollView setContentSize:CGSizeMake( * [slideImages count], self.view.frame.size.height)];
[scrollView addSubview:imageView]; // 首页是第0页,默认从第1页开始的。所以+320。。。 } } //scrollView的委托函数
-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
NSTimeInterval secondsPerDay = **;
NSDate *thire = [NSDate dateWithTimeIntervalSinceNow:secondsPerDay];
[fanyeTime setFireDate:thire]; CGFloat pagewidth = self.scrollView.frame.size.width;
int currentPage = floor((self.scrollView.contentOffset.x - pagewidth/ ([slideImages count]+)) / pagewidth) + ; NSLog(@"currentPage------>%d",currentPage);
pageControl.currentPage = currentPage; NSLog(@"slideImages count------>%d",[slideImages count]); if (currentPage==([slideImages count]-)){ [self tiaozhuan];
} }
//
-(void)tiaozhuan
{
JKNavigationController *navigationController = [[[JKNavigationController alloc] initWithRootViewController:[[[JKViewController alloc]init]autorelease]]autorelease];
navigationController.navigationBarHidden = YES;
[self presentViewController:navigationController animated:YES completion:nil]; } //pagecontrol的方法
-(void)turnPage
{
int page = pageControl.currentPage;
NSLog(@"page----->%d",page);
[self.scrollView scrollRectToVisible:CGRectMake(*page,,,) animated:NO];
if (page == ) {
[fanyeTime invalidate];
[NSTimer scheduledTimerWithTimeInterval: target:self selector:@selector(tiaozhuan) userInfo:nil repeats:YES]; } }
//定时器绑定方法
-(void)runTimePage
{
int page = pageControl.currentPage;
page++;
pageControl.currentPage = page;
[self turnPage];
} - (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end

2、接着是YCScroView类

YCScroView.h

#import <UIKit/UIKit.h>
@protocol TapImageDelegate <NSObject> -(void)tapImage:(int)index; @end @interface YCScroView : UIView @property (retain,nonatomic) id<TapImageDelegate>delegate; -(id)initWithArray:(NSArray*)array WithTitle:(NSString *)title WithFrame:(CGRect)frame;
@end

YCScroView.v

#import "YCScroView.h"
#define Max 10 @interface YCScroView() <UIScrollViewDelegate>
{
NSArray *_array;
int pageWidth,pageHight;
}
@property (strong,nonatomic)UIScrollView *scrollView;
@property (strong,nonatomic)NSMutableArray *slideImages;
@property (strong,nonatomic)UIPageControl *pageControl;
@property (strong,nonatomic)UITapGestureRecognizer *tap;
@end @implementation YCScroView
@synthesize scrollView,slideImages;
@synthesize pageControl;
@synthesize tap; -(id)initWithArray:(NSArray *)array WithTitle:(NSString *)title WithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
_array = array;
pageWidth = frame.size.width;
pageHight = frame.size.height; [self creatScollView];
}
return self;
} -(void)creatScollView
{
self.scrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(, , pageWidth, pageHight)];
scrollView.bounces = YES;
scrollView.pagingEnabled = YES;
scrollView.delegate = self;
scrollView.userInteractionEnabled = YES;
scrollView.showsHorizontalScrollIndicator = NO;
[self addSubview:scrollView];
slideImages = [NSMutableArray arrayWithArray:_array];
[slideImages retain];
self.pageControl = [[UIPageControl alloc]initWithFrame:CGRectMake(, pageHight-, , )];
[pageControl setCurrentPageIndicatorTintColor:[UIColor whiteColor]];
[pageControl setPageIndicatorTintColor:[UIColor grayColor]];
pageControl.numberOfPages = [_array count];
pageControl.currentPage = ;
// [pageControl addTarget:self action:@selector(turnPage) forControlEvents:UIControlEventValueChanged]; // 触摸mypagecontrol触发change这个方法事件
[self addSubview:pageControl]; for (int i =; i<[slideImages count]; i++) {
UIImageView *imageView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:[slideImages objectAtIndex:i]]];
imageView.frame = CGRectMake((pageWidth * i)+ pageWidth, , pageWidth, pageHight);
[scrollView addSubview:imageView]; // 首页是第0页,默认从第1页开始的。所以+320。。。
}
UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:[slideImages objectAtIndex:([slideImages count]-)]]];
imageView.frame = CGRectMake(, , pageWidth, pageHight);
[scrollView addSubview:imageView];
//取数组第一张图片,放在最后
imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:[slideImages objectAtIndex:]]];
imageView.frame = CGRectMake((pageWidth * ([slideImages count] + )) , , pageWidth, pageHight); // 添加第1页在最后 循环
[scrollView addSubview:imageView]; [scrollView setContentSize:CGSizeMake(pageWidth * ([slideImages count] + ), pageHight)]; // +上第1页和第4页 原理:4-[1-2-3-4]-1
[scrollView setContentOffset:CGPointMake(, )];
[self.scrollView scrollRectToVisible:CGRectMake(pageWidth,,pageWidth,pageHight) animated:NO]; [self addTapEventOnMyScrollView];
UIImageView *View=[[UIImageView alloc]initWithFrame:CGRectMake(, , pageWidth, )];
View.image=[UIImage imageNamed:@"huixian.png"];
[self addSubview:View]; UIImageView *View1=[[UIImageView alloc]initWithFrame:CGRectMake(, , , )];
View1.image=[UIImage imageNamed:@"lanxian.png"];
View1.tag=;
[self addSubview:View1]; } -(void)addTapEventOnMyScrollView;
{
tap = [[UIGestureRecognizer alloc] initWithTarget:self action:@selector(tapEvent)];
[scrollView addGestureRecognizer:tap];
} -(void)tapEvent
{
[self.delegate tapImage:pageControl.currentPage];
} -(void)scrollViewDidScroll:(UIScrollView *)scrollView
{
CGFloat pagewidth = self.scrollView.frame.size.width;
int page = floor((self.scrollView.contentOffset.x - pagewidth/([slideImages count]+))/pagewidth)+;
page --; // 默认从第二页开始
pageControl.currentPage = page;
} -(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
CGFloat pagewidth = self.scrollView.frame.size.width;
int currentPage = floor((self.scrollView.contentOffset.x - pagewidth/ ([slideImages count]+)) / pagewidth) + ;
if (currentPage==)
{
[self.scrollView scrollRectToVisible:CGRectMake( * [slideImages count],,,pageHight) animated:NO]; // 序号0 最后1页
}
else if (currentPage==([slideImages count]+))
{
[self.scrollView scrollRectToVisible:CGRectMake(,,,pageHight) animated:NO]; // 最后+1,循环第1页
} UIImageView* imageView=(UIImageView*)[self viewWithTag:];
[imageView removeFromSuperview]; UIImageView* imageview=[[UIImageView alloc]initWithImage:[UIImage imageNamed:@"lanxian.png"]];
imageview.frame=CGRectMake(pageControl.currentPage*, , , );
imageview.tag=;
[self addSubview:imageview];
} - (void)runTimePage
{
int page = pageControl.currentPage; // 获取当前的page
page++;
page = page > [slideImages count]- ? : page ;
pageControl.currentPage = page;
[self turnPage];
}
// pagecontrol 选择器的方法
- (void)turnPage
{
int page = pageControl.currentPage; // 获取当前的page
[self.scrollView scrollRectToVisible:CGRectMake(*(page+),,,) animated:NO]; // 触摸pagecontroller那个点点 往后翻一页 +1
}
-(void)dealloc{ [super dealloc];
} - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait);
} @end

这是来那个最主要的类,完成这两个类,基本上引导页就已经完成了。

代码下载 

IOS开发小功能1:引导页的开发的更多相关文章

  1. iOS - GitHub干货分享(APP引导页的高度集成 - DHGuidePageHUD - ②)

    距上一篇博客"APP引导页的高度集成 - DHGuidePageHUD - ①"的发布有一段时间了, 后来又在SDK中补充了一些新的内容进去但是一直没来得及跟大家分享, 今天来跟大 ...

  2. 网页引导:jQuery插件实现的页面功能介绍引导页效果

    现在很多网站不仅是介绍,更多的是有一些功能,怎么样让客户快速的知道网站有哪些功能呢?这里pagewalkthrough.js插件能帮我们实现,它是一个轻量级的jQuery插件,它可以帮助我们创建一个遮 ...

  3. jQuery插件实现的页面功能介绍引导页效果

    新产品上线或是改版升级,我们会在用户第一次使用产品时建立一个使用向导,引导用户如何使用产品,如使用演示的方式逐一介绍界面上的功能模块,从而提升了用户体验和产品的亲和力. Helloweba.com之前 ...

  4. iOS常用小功能

    CHENYILONG Blog 常用小功能 技术博客http://www.cnblogs.com/ChenYilong/ 新浪微博http://weibo.com/luohanchenyilong  ...

  5. iOS 常用小功能 总结

    常用小功能 iOS中的很多小功能都是非常简单的,几行代码就搞定了,比如打电话.打开网址.发邮件.发短信等 打电话 方法一(不被采用): 拨号之前会弹框询问用户是否拨号,拨完后能自动回到原应用 NSUR ...

  6. iOS - GitHub干货分享(APP引导页的高度集成 - DHGuidePageHUD - ①)

    好长时间没更新博客, 是时候来一波干货分享了;APP引导页话不多说每一个APP都会用到,分量不重但是不可缺少,不论是APP的首次安装还是版本的更新,首先展现给用户眼前的也就只有它了吧,当然这里讲的不是 ...

  7. IOS开发小功能2:二维码扫描界面的设计(横线上下移动)

    效果图如上,实现的是一个二维码扫描界面. 下面我贴出线条上下移动的代码,至于二维码的代码是用的第三方库. 首先是整体的结构: 注意下面的库文件一个都不能少,否则会报错. TLTiltHighlight ...

  8. iOS之小功能模块--彩虹动画进度条学习和自主封装改进

    前言: 首先展示一下这个iOS小示例的彩色进度条动画效果: 阅读本文先说说好处:对于基础不好的读者,可以直接阅读文末尾的"如何使用彩虹动画进度条"章节,然后将我封装好的这个功能模块 ...

  9. 【Android】Android开发小功能,倒计时的实现。时间计时器倒计时功能。

    作者:程序员小冰,GitHub主页:https://github.com/QQ986945193 新浪微博:http://weibo.com/mcxiaobing 首先给大家看一下我们今天这个最终实现 ...

随机推荐

  1. 使用sqlnet.ora限制IP访问

    他在最后一个超级遭遇了许多方法值,然后找到一个方法,在DB上限IP访问. http://blog.csdn.net/jacson_bai/article/details/18097805 ENV:   ...

  2. Android apk file

    apk file 事实上zip文件. 您可以使用unzip命令提取. unzip example1.apk -d ./example_dir tree . ├── AndroidManifest.xm ...

  3. 【百度地图API】如何制作一张魔兽地图!!——CS地图也可以,哈哈哈

    原文:[百度地图API]如何制作一张魔兽地图!!--CS地图也可以,哈哈哈 摘要: 你玩魔兽不?你知道如何做一张魔兽地图不?! 快来看此文吧! ---------------------------- ...

  4. openfire修改服务器名称方法

    1.登陆openfire管理页面,在主页面下方选择编辑属性,修改服务器名称为当前主机名称,点击保存属性,按页面提示重启服务器. 2.重启后,主页的服务器属性下的服务器名称出现一个叹号,鼠标放上去显示F ...

  5. addEventListener 与attachEvent

    第一:简单的通用方法(IE && FF) window.onload = function(){ var oDiv = document.getElementById("J_ ...

  6. Thrift实现C#通讯服务程序

    Thrift初探:简单实现C#通讯服务程序 好久没有写文章了,由于换工作了,所以一直没有时间来写博.今天抽个空练练手下~最近接触了下Thrift,网上也有很多文章对于Thrift做了说明:       ...

  7. 探讨css中repaint和reflow

    (个人blog迁移文章.) 前言: 页面设计中,不可避免的需要浏览器进行repaint和reflow.那到底什么是repaint和reflow呢.下面谈谈自己对repaint和reflow的理解,以及 ...

  8. Visual Studio 2015环境

    Visual Studio 2015环境搭建 2014年11月13日,微软发布了Visual Studio 2015 Preview,跟随者Visual Studio 2015 而来的是,.net 开 ...

  9. 腾讯QQ音乐网页版 音频初始化模块解压混淆js源码

    define("js/view/playerBar.js",function(t,e,o){ var i = t("js/lib/zepto.js"), a = ...

  10. DirectX:函数连接两个随机filter

    函数连接两个随机filter HRESULT ConnectFilters( IBaseFilter *pSrc, IBaseFilter *pDest ) { IPin *pIn = 0; IPin ...