引导页

作者: 箫声_筱昇 | 来源:发表于2016-04-23 11:55 被阅读137次

引导页

引导页是在程序第一次安装的时候呈现出来的画面.

  • 新建一个.pch.用于做程序中的声明.声明这几个变量
#import "RootViewController.h"
#import "GuideViewController.h"

#define kUserDefaults [NSUserDefaults standardUserDefaults]
//定义长
#define kScreenWidth [UIScreen mainScreen].bounds.size.width
//定义高
#define kScreenHeight [UIScreen mainScreen].bounds.size.height
//自定义颜色变量.随机颜色
#define MYCOLOR(r,g,b,a) [UIColor colorWithRed:r green:g blue:b alpha:a]

在 AppDelegate.m中

//进行判断,如果是第一次打开此程序.则显示引导页.如果不是第一次打开,则直接显示程序页面
if(kUserDefaults boolForKey:@"isFirstLaunch"){
//根据键来判断,结果为 yes.说明不是首次加载.加载根式如控制器
RootViewController *rootVC = [[RootViewController alloc] init];
self.window.rootViewController = [[UINavigationController alloc] initWithRootViewController:rootVC];
}else{
//是首次加载,加载引导页.并且将 userDefaults 的值改为 yes.
GuideViewController *guideVC = [[GuideViewController alloc] init];
self.window.rootViewController = guideVC;
[kUserDefaults setBool:YES forKey:@"isFirstLaunch"];
}

在 GuideViewController.h中

#import "AppDelegate.n"
@interface GuideViewController ()
//声明一个 scrollview 的全局变量
@property (nonatomic, strong) UIScrollView *guideScrollView;
@end
- (void)viewDidLoad{
//初始化 scrollview. 页面大小为view.frame
 _guideScrollView = [[UIScrollView alloc] initWithFrame:self.view.frame];
一面的偏移量.
 _guideScrollView.contentSize =CGSizeMake(kScreenWidth *3, 0);
    //分页效果
 _guideScrollView.pagingEnabled = YES;
    //隐藏指示条
_guideScrollView.showsHorizontalScrollIndicator = NO;
//添加子视图
for (int i = 0; i < 3; i++) {
UIView *subView = [[UIView alloc] initWithFrame:CGRectMake(i * kScreenWidth, 0, kScreenWidth, kScreenHeight)];
subView.backgroundColor = MYCOLOR(arc4random()% 256/255.0, arc4random()% 256/255.0, arc4random()% 256/255.0, 1.0);
if (i == 2) {
UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
[button setFrame:CGRectMake(100,500, 200, 50)];
[button setTitle:@"马上体验精彩生活" forState: UIControlStateNormal];
//添加回调方法.
[button addTarget:self action:@selector(huiddenGuiVC) forControlEvents:UIControlEventTouchUpInside];
//注意:button是要添加在subview 上的.
[subView addSubview:button];
        }
        [self.guideScrollView addSubview:subView];
  }
    //在 for 循环外部,将滚动视图添加到当前页面
    [self.view addSubview:self.guideScrollView];
}

#pragma mark-----huiddenGuiVC按钮的回调方法.
- (void)huiddenGuiVC{
    //置换 window 的根视图控制器.
AppDelegate *appDelegate = [UIApplication sharedApplication].delegate;
appDelegate.window.rootViewController = [[UINavigationController alloc] initWithRootViewController:[[RootViewController alloc] init]];
    
}

相关文章

  • 引导页

    // // ViewController.m // 引导页_课堂练习 // // Created by 张羽婷 o...

  • 引导页

    引导页是用户第一次使用app时,引导用户使用的页面,这个界面通常加载到进入界面的上面。我这个引导页是一个View,...

  • 引导页

    AppDelegate.m #import "AppDelegate.h" #import "ViewContro...

  • 引导页

    判断版本号 引导页界面 点击方法

  • 引导页

    引导页 引导页是在程序第一次安装的时候呈现出来的画面. 新建一个.pch.用于做程序中的声明.声明这几个变量 在 ...

  • 引导页

    sharedPreferences = getSharedPreferences("ues", MODE_PRIV...

  • 引导页

    引导页设计 一般不会超过5页。作用:让用户了解产品价值和功能,引导用户更快进入使用环境。 按照功能分类: 1.功能...

  • 引导页

    第一种方法: 通过点击按键的方式进入应用### 该方法需要两个视图控制器,一个用来创建引导页的滚动视图,另一个创建...

  • 引导页

  • 引导页

    APP启动视屏 APP第一次启动播放视频欢迎 https://github.com/Zws-China/start...

网友评论

本文标题:引导页

本文链接:https://www.haomeiwen.com/subject/lhgxrttx.html