//
// 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. Oracle数据库的启动和关闭

    深刻理解Oracle数据库的启动和关闭 Oracle数据库提供了几种不同的数据库启动和关闭方式,本文将详细介绍这些启动和关闭方式之间的区别以及它们各自不同的功能. 一.启动和关闭Oracle数据库 对 ...

  2. Arduino周边模块:执行部件(舵机、直流电机、步进电机)

    Arduino周边模块:执行部件 Arduino周边模块:执行部件 嵌入式系统的构成 如今已经有各种各样的基于Arduino的嵌入式系统, 比如:智能小车.3D打印机.机器人,甚至还有基于Arduin ...

  3. Javascript 字符串浏览器兼容问题

    先看下不兼容的写法,若我想获取某个字符串的第几位 var str='aavvvcc'; console.info(str[0]); 这种写法 在IE 7以下的浏览器都不兼容,以下提供浏览器全兼容的方式 ...

  4. [转]easyui常用控件及样式收藏

    CSS类定义: div easyui-window                               window窗口样式 属性如下: 1)       modal:是否生成模态窗口.tru ...

  5. 【Chromium中文文档】多进程资源加载

    多进程资源加载(需要更新) 转载请注明出处:https://ahangchen.gitbooks.io/chromium_doc_zh/content/zh//General_Architecture ...

  6. android 获取http网络图片保存png

    1.android 获取网络图片的方式很多,普通网络通信的方式都可以用在获取网络图片上. android   http获取数据常用的方式: 1.Apache接口(HttpClient) 2.标准Jav ...

  7. 使用C#开发Metro 风格应用的路线图 -- 触屏操作

    原文 http://www.cnblogs.com/icuit/archive/2012/05/01/2478312.html win8支持多点触摸技术,而我们在屏幕上所做的各种操作,也最终转换为输入 ...

  8. javascript获取url地址问好后面的值,包括问号

    javascript获取url地址问好后面的值,包括问号 <!DOCTYPE html> <html lang="en"> <head> < ...

  9. IE6兼容性问题及IE6常见bug详细汇总---转载

    1.IE6怪异解析之padding与border算入宽高 原因:未加文档声明造成非盒模型解析 解决方法:加入文档声明<!doctype html> 2.IE6在块元素.左右浮动.设定mar ...

  10. Linux 内核优化

    声明:本文档来自互联网整理部份加自已实验部份所得: TCP 相关部份   经常使用名词说明: retries(再试).   TCP server <---> client通信状态      ...