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 甚至一个互联网公司运行的健康程度和发展动能.启动流程的体验决定了用户的第一印象,在一定程度上影响了用户活跃度和留存率.因此,确保启 ...
随机推荐
- Linux下多任务间通信和同步-消息队列
Linux下多任务间通信和同步-消息队列 嵌入式开发交流群280352802,欢迎加入! 简介 消息队列简称为队列.消息队列就是一些消息的列表.用户可以在消息队列中添加消息和读取消息等.从这点上看,消 ...
- C++设计模式之建造模式
#include <iostream>using namespace std; class ApplePhone { public: virtual void buildCamera()= ...
- genymotion 模拟器 真是牛叉了 速度超快啊!!! 不解释了!建议大家速度去体验一把吧!
已经有人写了blog了 我就不再赘述了,详情去这里看去吧!! android genymotion模拟器怎么使用以及和google提供的模拟器性能对比 http://blog.csdn.net/ ...
- #include <thread>
1 detach 脱离当前主线程,自由执行,乱序; 2 join() 等待模式,执行完再执行下一个 3 std::this_thread::get_id() 获取当前线程编号 4 std::threa ...
- 【Deep Learning】genCNN: A Convolutional Architecture for Word Sequence Prediction
作者:Mingxuan Wang.李航,刘群 单位:华为.中科院 时间:2015 发表于:acl 2015 文章下载:http://pan.baidu.com/s/1bnBBVuJ 主要内容: 用de ...
- 如何在VMware虚拟机上安装Linux操作系统(Ubuntu)
作为初学者想变为计算机大牛非一朝一夕,但掌握基本的计算机操作和常识却也不是多么难的事情.所以作为一名工科男,为了把握住接近女神的机会,也为了避免当白痴,学会装系统吧!of course为避免把自己的电 ...
- 对XXX(数字)安全卫士实在是忍无可忍了,为什么一定要像日本鬼子强奸妇女一样强奸我们这些弱小者
一直一来对XXX(数字)安全卫士非常痛恨,无耻,恶心,没有底线,还有对待我们这些弱小者,就像当年日本鬼子强奸妇女一样,血粼粼的虐杀我们这些弱小者,无法反抗,又必须接受. 你强制杀掉别人的ADB 就算了 ...
- My97DaePicker 用js实现文本框日期相减求天数
<tr> <td align="center" style="background-color: #cccccc;font ...
- HTML系列(七):多媒体
一.video标签 H5新增了video实现在线播放视频的功能: 代码示例: <video controls="controls"> <source src=&q ...
- 【百度地图API】获取行政区域的边界
);map.addControl(new BMap.NavigationControl({type: BMAP_NAVIGATION_CONTROL_SMALL}));map.enableScroll ...