//
// GuideViewController.h
// Guide
//
// Created by twb on 13-9-17.
// Copyright (c) 2013年 twb. All rights reserved.
// #import <UIKit/UIKit.h> @interface GuideViewController : UIViewController <UIScrollViewDelegate> @property (nonatomic, strong) UIScrollView *scrollView;
@property (nonatomic, strong) UIPageControl *pageControl;
@property (nonatomic, strong) NSMutableArray *images; + (GuideViewController *)shareInstance;
+ (void)show;
+ (void)hide; @end
//
// GuideViewController.m
// Guide
//
// Created by twb on 13-9-17.
// Copyright (c) 2013年 twb. All rights reserved.
// #import "GuideViewController.h" @interface GuideViewController () @property (nonatomic, assign) BOOL animating; @end @implementation GuideViewController + (GuideViewController *)shareInstance
{
@synchronized(self)
{
static GuideViewController *sharedGuide = nil;
if (sharedGuide == nil)
{
sharedGuide = [[self alloc] initWithNibName:@"GuideViewController" bundle:nil];
}
return sharedGuide;
}
} + (void)show
{
[[GuideViewController shareInstance].scrollView setContentOffset:CGPointMake(0.0f, 0.0f)];
[[GuideViewController shareInstance] showGuide];
} + (void)hide
{
[[GuideViewController shareInstance] hideGuide];
} - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization }
return self;
} - (void)viewDidLoad
{
[super viewDidLoad]; self.view.backgroundColor = kClearColor; // Do any additional setup after loading the view from its nib.
[self setupContent];
[self setupScrollView];
[self setupPageControl];
[self setupScrollViewContent];
} - (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
} - (void)viewDidUnload
{
[self setScrollView:nil];
[self setPageControl:nil];
[super viewDidUnload];
} #pragma mark - setup part. - (void)setupContent
{
// These images retrieve from server. it is empty for just now.
self.images = [NSMutableArray arrayWithArray:@[@"Default.png", @"Default.png", @"Default.png", @"Default.png"]];
} - (void)setupScrollView
{
self.scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, kScreenWidth, kScreenHeight - kScreenStatusBarHeight)];
self.scrollView.pagingEnabled = YES;
self.scrollView.delegate = self;
self.scrollView.backgroundColor = kClearColor;
self.scrollView.showsHorizontalScrollIndicator = NO;
self.scrollView.showsVerticalScrollIndicator = NO;
// self.scrollView.backgroundColor = kOrangeColor;
self.scrollView.contentSize = CGSizeMake(kScreenWidth * self.images.count, kScreenHeight - kScreenStatusBarHeight);
[self.view addSubview:self.scrollView];
} - (void)setupPageControl
{
self.pageControl = [[UIPageControl alloc] initWithFrame:CGRectMake(0.0f, self.scrollView.frame.size.height - 30.0f, kScreenWidth, 30.0f)];
self.pageControl.hidesForSinglePage = YES;
self.pageControl.numberOfPages = self.images.count;
[self.pageControl addTarget:self action:@selector(pageChanged:) forControlEvents:UIControlEventValueChanged];
[self.view addSubview:self.pageControl];
} - (void)setupScrollViewContent
{
for (NSInteger i = 0; i < self.images.count; i++)
{
UIImageView *iv = [[UIImageView alloc] initWithFrame:CGRectMake(i * kScreenWidth, 0.0f, self.scrollView.frame.size.width, self.scrollView.frame.size.height)];
iv.userInteractionEnabled = YES;
iv.image = kImageNamed(self.images[i]);
if (i % 2)
{
iv.backgroundColor = kLightGrayColor;
}
else
{
iv.backgroundColor = kGrayColor;
}
[self.scrollView addSubview:iv]; if (i == self.images.count - 1)
{
// the end page.
[iv addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(enter:)]];
}
}
} #pragma mark - Common part. - (CGRect)onScreenFrame
{
return [UIScreen mainScreen].applicationFrame;
} - (CGRect)offScreenFrame
{
CGRect frame = [self onScreenFrame];
switch ([UIApplication sharedApplication].statusBarOrientation)
{
case UIInterfaceOrientationPortrait:
frame.origin.y = frame.size.height;
break;
case UIInterfaceOrientationPortraitUpsideDown:
frame.origin.y = -frame.size.height;
break;
case UIInterfaceOrientationLandscapeLeft:
frame.origin.x = frame.size.width;
break;
case UIInterfaceOrientationLandscapeRight:
frame.origin.x = -frame.size.width;
break;
}
return frame;
} - (UIWindow *)mainWindow
{
UIApplication *app = [UIApplication sharedApplication];
if ([app.delegate respondsToSelector:@selector(window)])
{
return [app.delegate window];
}
else
{
return [app keyWindow];
}
} #pragma mark - Event part. - (void)enter:(UITapGestureRecognizer *)sender
{
[self hideGuide];
self.dataManager.defaults.firstLaunch = YES;
} - (void)showGuide
{
if (!self.animating)
{
[GuideViewController shareInstance].view.frame = [self offScreenFrame];
[[self mainWindow] addSubview:[GuideViewController shareInstance].view];
self.animating = YES;
[UIView animateWithDuration:0.25f animations:^{
[GuideViewController shareInstance].view.frame = [self onScreenFrame];
} completion:^(BOOL finished) {
self.animating = NO;
}];
}
} - (void)hideGuide
{
if (!self.animating)
{
self.animating = YES;
[UIView animateWithDuration:0.40f animations:^{
#if 0
[GuideViewController shareInstance].view.frame = [self offScreenFrame];
#else
[GuideViewController shareInstance].view.transform = CGAffineTransformMakeScale(1.25f, 1.25f);
[GuideViewController shareInstance].view.alpha = 0.0f;
#endif
} completion:^(BOOL finished) {
[[GuideViewController shareInstance].view removeFromSuperview];
self.animating = NO;
}];
}
} - (void)pageChanged:(UIPageControl *)sender
{
NSInteger page = sender.currentPage;
[self.scrollView setContentOffset:CGPointMake(page * kScreenWidth, 0.0f) animated:YES];
} #pragma mark - UIScrollViewDelegate - (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
CGFloat dx = scrollView.contentOffset.x;
NSInteger page = dx / kScreenWidth; self.pageControl.currentPage = page;
} @end

如何使用?

在 "AppDelegate.m"文件中,

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch. // ... // Show Guide?
if (!self.dataManager.defaults.firstLaunch)
{
[GuideViewController show];
} return YES;
}

iOS 首次启动画面,新装或更新用户可以通过它查看简介。的更多相关文章

  1. 【IOS】启动画面

    总述: 两种方式,一种是使用系统自带的.按规则定义启动图片名称就可以,显示为1秒,要想延长时间,用[nsthread ​ sleepForTimeInterval:5.0] ,还有一种就是自己定义ui ...

  2. IOS - 首次启动程序出现的画面介绍

    1.在appdelegate.m中找到 “application:didFinishLaunchingWithOptions:” 通过NSUserDefaults 来进行判断 if (![[NSUse ...

  3. IOS 制作启动画面

    启动方式简述 IOS 8 及之前: Launch Images Source方式, IOS8 及之后:    1, Launch Images Source方式 : 2 , LaunchScreen. ...

  4. IOS的启动画面的适配问题

    iPhone4,iPhone4s 分辨率960*640 长宽比1.5iPhone5,iPhone5s 分辨率1136*640 长宽比1.775iPhone6 分辨率1334*750 长宽比1.778i ...

  5. 在iOS App 中添加启动画面

    你可以认为你需要为启动画面编写代码,然而Apple 让你可以非常简单地在Xcode中完成.不需要编写代码,你仅需要在Xcode中进行一些配置. 1.什么是启动画面(Splash Screen)? 启动 ...

  6. iOS7的启动画面设置及asset catalogs简介

    如果上网搜索一下“iOS App图标设置”或者“iOS App启动画面设置”肯定能找到不少文章,但内容大多雷同,就是让你按照某种尺寸制作若干张png图片,再按照苹果的命名规范,加入到项目中去,一行代码 ...

  7. iOS LaunchScreen启动图设置

    新建的iOS 项目启动画面默认为LaunchScreen.xib 如果想实现一张图片作为启动页,如下图 如果启动不行  记得clear 一下工程 是启动页停留一段时间  只需要在 AppDelegat ...

  8. iOS开发 首次启动显示用户引导,第二次启动直接进入App,UIScrollView,UIPageControl,NSUserDefaults

    首先创建一个引导图的控制器类 UserGuideViewController.h和UserGuideViewController.m #import <UIKit/UIKit.h> #im ...

  9. 马蜂窝 iOS App 启动治理:回归用户体验

    增长.活跃.留存是移动 App 的常见核心指标,直接反映一款 App 甚至一个互联网公司运行的健康程度和发展动能.启动流程的体验决定了用户的第一印象,在一定程度上影响了用户活跃度和留存率.因此,确保启 ...

随机推荐

  1. iMac Termanel命令まとめ

    1.mac环境下命令的使用ls -l -a   列出指定目录下文件           -l 显示文件的详细信息           -a 显示目录下所有文件(包括隐藏文件)           -d ...

  2. 自学HTML5第二节(标签篇---新增标签详解)

    HTML5新增标签: <article> 标签 规定独立的自包含内容.一篇文章应有其自身的意义,应该有可能独立于站点的其余部分对其进行分发. <article> 元素的潜在来源 ...

  3. Vim 缓冲区与窗口 操作

    ##############缓冲区 :e(:open) 打开新缓冲区 :ls (:buffers) 列出列表内所有缓冲区/bs /bv /be(BufExplore快捷键) :b 2(:buffer ...

  4. Orchard 源码探索(Localization)之国际化与本地化

    本地化与国际化 基本上相关代码都在在Orchard.Framework.Localization中. T("english")是如何调用到WebViewPage.cs中的Local ...

  5. IC卡存储器介绍

    自从80年代中期出现IC电话卡后,基本已取代了原来流行的电话磁卡,磁卡存在存在严重的安全问题,已逐步淘汰.即使IC电话卡,也不能算很安全,卡内所有数据只要有简单的读写装置并按时序操作都能读取,事实上电 ...

  6. java.util.zip.GZIPInputStream.readUByte,Not in GZIP format错误处理

    问题一: 使用webclient抓取网页时报错:(GZIPInputStream.java:207) atjava.util.zip.GZIPInputStream.readUShort(GZIPIn ...

  7. PHPExcel 多工作表 导出

    //浏览器输出excel header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet ...

  8. Centos6.8下安装oracle_11gr2版主要过程

    安装前准备 下载oracle版本 地址:http://docs.oracle.com/cd/E21901_01/index.html ,下载2个文件分别是 linux.x64_11gR2_databa ...

  9. Android TextView drawableLeft 在代码中实现

    方法1 Drawable drawable= getResources().getDrawable(R.drawable.drawable); /// 这一步必须要做,否则不会显示. drawable ...

  10. CentOS 安装Node.js

    先安装gcc-c++编译环境和openssl yum install gcc-c++ openssl-devel 然后 下载包并解压 cd /usr/local/src wget http://nod ...