制作引导页[1]

简介:

制作引导页[1]

制作引导页的核心都是将视图控件加载在UIWindow上显示,在制作引导页[1]中,我们先用最容易理解的方式来制作引导页:)

效果:

源码:

AppDelegate.m

//
//  AppDelegate.m
//  Show
//
//  Copyright (c) 2014年 Y.X. All rights reserved.
//

#import "AppDelegate.h"
#import "RootViewController.h"

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    self.window.rootViewController = [RootViewController new];
    
    self.window.backgroundColor = [UIColor whiteColor];
    [self.window makeKeyAndVisible];
    return YES;
}

@end

RootViewController.m
//
//  RootViewController.m
//  Show
//
//  Copyright (c) 2014年 Y.X. All rights reserved.
//

#import "RootViewController.h"

@interface RootViewController ()

@end

@implementation RootViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
}

- (void)viewDidAppear:(BOOL)animated
{
    // 保证只运行一次
    [self scrollView];
}

- (void)scrollView
{
    CGRect rect    = self.view.window.bounds;
    CGFloat width  = rect.size.width;
    CGFloat height = rect.size.height;
    
    // 初始化scrollView
    UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:rect];
    scrollView.pagingEnabled = YES;
    scrollView.tag           = 0x77;
    scrollView.contentSize   = CGSizeMake(width * 3, height);
    
    // 添加一些控件
    for (int i = 0; i < 3; i++)
    {
        UIView *tmp         = [[UIView alloc] initWithFrame:CGRectMake(i*width, 0, width, height)];
        tmp.backgroundColor = [UIColor colorWithRed:arc4random()%255/255.f
                                              green:arc4random()%255/255.f
                                               blue:arc4random()%255/255.f
                                              alpha:1];
        
        if (i == 2)
        {
            YXButton *button = [[YXButton alloc] initWithFrame:CGRectMake(0, 0, 140, 30)];
            button.titleLabel.font = [UIFont fontWithName:@"HelveticaNeue-Thin"
                                                     size:20.f];
            button.layer.cornerRadius = 3.f;
            [button addTarget:self
                       action:@selector(buttonEvent:)
             forControlEvents:UIControlEventTouchUpInside];
            [button setBackgroundColor:[UIColor blackColor]
            highlightedBackgroundColor:[UIColor whiteColor]];
            [button setNormalTitleColor:[UIColor whiteColor]
                  highlightedTitleColor:[UIColor blackColor]
                     disabledTitleColor:nil];
            [button setNormalTitle:@"YouXianMing"
                  highlightedTitle:@"YouXianMing"
                     disabledTitle:@"YouXianMing"];
            button.center = self.view.center;
            [tmp addSubview:button];
        }
        
        [scrollView addSubview:tmp];
    }
    
    // 添加到UIWindow当中
    [self.view.window addSubview:scrollView];
}

- (void)buttonEvent:(UIButton *)button
{
    UIScrollView *scrollView = (UIScrollView *)[self.view.window viewWithTag:0x77];
    scrollView.userInteractionEnabled = NO;
    
    // 动画
    [UIView animateWithDuration:2.0 animations:^{
        scrollView.alpha = 0.f;
    } completion:^(BOOL finished) {
        // 从UIWindow上移除这个scrollView
        [scrollView removeFromSuperview];
    }];
}

@end

几个需要注意的地方:

在RootViewController的viewDidAppear方法中加载(因为只有在viewDidAppear的时候UIWindow才会接管这个RootViewController)

要确保添加在UIWindow上

最后记得从UIWindow上移除掉

很简单,对吧:)

目录
相关文章
|
数据可视化
|
小程序 开发者
如何制作一个闪屏页面
闪屏(Splash)指的是当你打开一个应用时,首先映入眼帘的那个界面。通常闪屏页面都会比较简单,因为要一闪而过(这大概就是为什么叫做闪屏了),一般都会放置产品的 LOGO,在游戏中通常会放置游戏制作团队或者工作室的 LOGO。
235 0
|
iOS开发 前端开发 敏捷开发
『精品素材』20套免费的网页小图标素材下载
  在网页设计工作中,图标设计是最耗时的任务之一,但幸运的是网络上有很多慷慨的设计师分享的现成的免费小图标素材包可以下载使用。下面这个列表收集了20套免费的网页小图标,记得分享和推荐啊。 您可能感兴趣的相关文章 10套华丽的Windows8 Metro风格图标 让人爱不释手的13套精美网...
1118 0
|
Java
简单制作网页分享按钮
话说这是一个人际互联的时代,SNS 类的社交网络大行其道。页面作为一种资源怎么不会参与到社交网络的分享中呢?于是我们看到页面都会提供一个分享功能,如我正在写的 CSDN 博文,出来就会有: 虽然现在有不少服务是专门做些分享按钮的,功能比较强大,包括统计的功能也有,但 Google 一番之后,发现其原理无非就是几张 icon 图片+连接,简单得很——于是就想自己来干,过把手瘾。
957 0
|
前端开发
HTML+CSS制作漂浮的对话框
HTML+CSS制作漂浮的对话框
|
JavaScript 前端开发 HTML5
14套新鲜出炉的网页图标素材下载
  每个设计师的工具箱都有收藏设计素材,特别是漂亮的图标集,图标对于网页设计非常有用。今天这篇文章要与大家分享的是14套新鲜出炉的网页图标素材,可以免费下载使用,记得收藏起来哦 :) Hand Drawn Web icons 48px web iconset The Aristocra...
923 0
|
9月前
微信小游戏制作工具中关于背景图的设置
微信小游戏制作工具中关于背景图的设置
262 0
|
9月前
|
前端开发
实践任务:项目介绍与项目准备+制作网页头部和导航+制作banner和最新更新栏目+制作苹果之家栏目+制作底部版权区域与CSS代码优化+制作Apple独家栏目
实践任务:项目介绍与项目准备+制作网页头部和导航+制作banner和最新更新栏目+制作苹果之家栏目+制作底部版权区域与CSS代码优化+制作Apple独家栏目
64 1

热门文章

最新文章