iOS 首次启动画面,新装或更新用户可以通过它查看简介。
//
// 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 首次启动画面,新装或更新用户可以通过它查看简介。的更多相关文章
- 【IOS】启动画面
		
总述: 两种方式,一种是使用系统自带的.按规则定义启动图片名称就可以,显示为1秒,要想延长时间,用[nsthread  sleepForTimeInterval:5.0] ,还有一种就是自己定义ui ...
 - IOS - 首次启动程序出现的画面介绍
		
1.在appdelegate.m中找到 “application:didFinishLaunchingWithOptions:” 通过NSUserDefaults 来进行判断 if (![[NSUse ...
 - IOS 制作启动画面
		
启动方式简述 IOS 8 及之前: Launch Images Source方式, IOS8 及之后: 1, Launch Images Source方式 : 2 , LaunchScreen. ...
 - IOS的启动画面的适配问题
		
iPhone4,iPhone4s 分辨率960*640 长宽比1.5iPhone5,iPhone5s 分辨率1136*640 长宽比1.775iPhone6 分辨率1334*750 长宽比1.778i ...
 - 在iOS App 中添加启动画面
		
你可以认为你需要为启动画面编写代码,然而Apple 让你可以非常简单地在Xcode中完成.不需要编写代码,你仅需要在Xcode中进行一些配置. 1.什么是启动画面(Splash Screen)? 启动 ...
 - iOS7的启动画面设置及asset catalogs简介
		
如果上网搜索一下“iOS App图标设置”或者“iOS App启动画面设置”肯定能找到不少文章,但内容大多雷同,就是让你按照某种尺寸制作若干张png图片,再按照苹果的命名规范,加入到项目中去,一行代码 ...
 - iOS LaunchScreen启动图设置
		
新建的iOS 项目启动画面默认为LaunchScreen.xib 如果想实现一张图片作为启动页,如下图 如果启动不行 记得clear 一下工程 是启动页停留一段时间 只需要在 AppDelegat ...
 - iOS开发 首次启动显示用户引导,第二次启动直接进入App,UIScrollView,UIPageControl,NSUserDefaults
		
首先创建一个引导图的控制器类 UserGuideViewController.h和UserGuideViewController.m #import <UIKit/UIKit.h> #im ...
 - 马蜂窝 iOS App 启动治理:回归用户体验
		
增长.活跃.留存是移动 App 的常见核心指标,直接反映一款 App 甚至一个互联网公司运行的健康程度和发展动能.启动流程的体验决定了用户的第一印象,在一定程度上影响了用户活跃度和留存率.因此,确保启 ...
 
随机推荐
- npm 安装参数中的-save和 -save-dev
			
当你为你的模块安装一个依赖模块时,正常情况下你得先安装他们(在模块根目录下npm install module-name),然后连同版本号手动将他们添加到模块配置文件package.json中的依赖里 ...
 - PHP中字符串补齐为定长
			
方法一 for ($i=0; $i<100; $i++) { $index = sprintf('%04d', $i); echo $index.'<br />'; } 方法二 fo ...
 - composer时间长了,提示需要升级,结果问题来了
			
今天重新开始之前的laravel项目,结果composer提示需要升级,于是 composer selfupdate 结果提示无法连接目标库,查阅composer官网,发现之前的库地址已经启用了ssl ...
 - 学习iOS开发的前言
			
一.什么是iOS 要想学习iOS开发,首先要搞清楚什么是iOS.iOS其实是一款操作系统,就像平时我们在电脑上用的XP.Win7,都是操作系统. 那什么是操作系统呢?操作系统其实是一种软件,是直接运行 ...
 - 微软Windows 7 “可启动U盘”制作工具及使用方法,非常的简单
			
目前,用“可启动U盘”替代光驱光盘安装操作系统,已经成为一种时尚(至少对没有刻录机或不愿购买光碟的群体是这样).制作“可启动U盘”的方法和工具很多,区别无非是制作的难易程度和对“U盘类型”的支持程度. ...
 - Unix/Linux环境C编程入门教程(17)  Gentoo LinuxCCPP开发环境搭建
			
1. Gentoo Linux是一套通用的.快捷的.完全免费的Linux发行,它面向开发人员和网络职业人员.与其他发行不同的是,Gentoo Linux拥有一套先进的包管理系统叫作Portage.在B ...
 - [Leetcode][Python]26: Remove Duplicates from Sorted Array
			
# -*- coding: utf8 -*-'''__author__ = 'dabay.wang@gmail.com' 26: Remove Duplicates from Sorted Array ...
 - 一个神奇的bug
			
在使用touch命令创建了一个swift文件后,如果用xcode打开该文件,然后输入 #!/usr/bin/env xcrun swift 接着你就会发现,xcode崩溃了.
 - 今天,Java编程周末提高班(第一期)正式结束
			
Java编程周末提高班(第一期),走过了近两个月历程,一共同拥有68人次学生周末到老师家进行Java学习与交流.近距离的和一群年轻的学习接触,收获非常多,特别是对以后教学的改进.在学习的闲暇.大家自己 ...
 - JavaScript之<noscript>标签简介
			
早期浏览器都面临一个特殊的问题,即当浏览器不支持JavaScript时如何让页面平稳的退化.对这个问题的终极方案就是创造一个<noscript>元素,用以在不支持或支持但禁用了JavaSc ...