//
// 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. 字节数转换为b,kb,mb,gb的方法 通用的手机流量计算方法

    //通用的手机流量计算方法 private String byteToMB(long size){ long kb = 1024; long mb = kb*1024; long gb = mb*10 ...

  2. Android 6.0 以及HttpClient

    Android 6.0 SDK,API Level 是 23.更新之后,就可以修改 compileSdkVersion 和targetSdkVersion 到 23 体验新的特性了. 同时 Andro ...

  3. 我来讲讲在c#中怎么进行xml文件操作吧,主要是讲解增删改查!

    我把我写的四种方法代码贴上来吧,照着写没啥问题. 注: <bookstore> <book> <Id>1</Id> <tate>2010-1 ...

  4. SilverLight搭建WCF聊天室详细过程

    收藏SL双工通信例子教程 SilverLight 4正式版发布给开发人员带来了更多功能,并且4已经支持NET.TCP协议,配合WCF开发高效率的交互应用程序已经不再是难事,本系列文章主要针对已经完成的 ...

  5. ArcEngine栅格和矢量渲染(含可视化颜色带)

    使用ArcEngine9.3开发的栅格和矢量的渲染. 开发环境:ArcEngine9.3,VS2008. 功能:栅格(拉伸和分级)和矢量(简单.唯一值.分级.比例)渲染. 开发界面如图所示. 图1 主 ...

  6. TLSAlloc()

    为什么要有TLS?原因在于,进程中的全局变量与函数内定义的静态(static)变量,是各个线程都可以访问的共享变量.在一个线程修改的内存内容,对所有线程都生效.这是一个优点也是一个缺点.说它是优点,线 ...

  7. 百度云是用SOUI开发的产品

    http://www.cnblogs.com/setoutsoft/p/4155997.html

  8. docker 私有仓库镜像的存储位置

    docker 私有仓库的镜像 是存储在5739360d1030 registry "docker-registry" 3 days ago Up 28 hours 0.0.0.0: ...

  9. virsh VMI deploy data serial xml

    <domain type='kvm' xmlns:qemu='http://libvirt.org/schemas/domain/qemu/1.0'>        <name> ...

  10. Go语言简单的TCP编程

    前期准备 需要import "net"包 IP类型,其中一个重要的方法是IP.ParseIP(ipaddr string)来判断是否是合法的IP地址 TCP Client func ...