制作引导页[3]

简介:

制作引导页[3]

第三种方法是将整个引导页写到一个controller中,是通用性最高的一种写法:)

效果:

源码:

AppDelegate.m

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

#import "AppDelegate.h"
#import "WelcomeViewController.h"

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    
    // 接管控制器
    self.window.rootViewController = [WelcomeViewController new];
    self.window.backgroundColor = [UIColor whiteColor];
    
    // 让视图可见
    [self.window makeKeyAndVisible];
    
    return YES;
}

@end

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

#import "WelcomeViewController.h"
#import "RootViewController.h"

@interface WelcomeViewController ()

@end

@implementation WelcomeViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
}

- (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.window.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];
        
        // 切换视图控制器
        self.view.window.rootViewController = [RootViewController new];
    }];
}

@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];
    [UIView animateWithDuration:2 animations:^{
        self.view.backgroundColor = [UIColor blackColor];
    }];
}

@end

几个需要注意的地方:

动画结束后要切换视图控制器

过渡更自然

 

总结:

这几篇教程制作引导页的核心都是在UIWindow上加载视图或者视图控制器,就是这么容易哦:)

目录
相关文章
|
6天前
宽屏好看的个人引导页源码
宽屏好看的个人引导页源码,源码由HTML+CSS+JS组成,记事本打开源码文件可以进行内容文字之类的修改,双击html文件可以本地运行效果
22 5
宽屏好看的个人引导页源码
|
4月前
HTML+CSS+JS实现十款好看的登录注册界面模板,赶紧收藏起来吧!(一)
HTML+CSS+JS实现十款好看的登录注册界面模板,赶紧收藏起来吧!
|
4月前
微信小游戏制作工具中关于背景图的设置
微信小游戏制作工具中关于背景图的设置
104 0
|
4月前
HTML+CSS+JS实现十款好看的登录注册界面模板,赶紧收藏起来吧!(二)
HTML+CSS+JS实现十款好看的登录注册界面模板,赶紧收藏起来吧!
|
4月前
水晶头制作
水晶头制作。
124 44
|
11月前
|
开发工具 UED 开发者
在微信小游戏制作工具中实现各种效果和功能的按钮
在游戏设计中有一个名词叫“反馈”,大体就是指当玩家在进行游戏时,游戏所给予玩家的一些东西,比如常见的在点击按钮时,按钮会变换颜色,或进行缩放,或播放音效等等。总之,不论玩家在游戏中进行任何的操作,游戏都应该给予玩家一个合理的反馈。让玩家能够明白他的操作所获得的结果是什么。
269 0
|
11月前
|
小程序 开发者
如何制作一个闪屏页面
闪屏(Splash)指的是当你打开一个应用时,首先映入眼帘的那个界面。通常闪屏页面都会比较简单,因为要一闪而过(这大概就是为什么叫做闪屏了),一般都会放置产品的 LOGO,在游戏中通常会放置游戏制作团队或者工作室的 LOGO。
146 0
|
自然语言处理 C++
制作有道词典——标题栏
制作有道词典——标题栏
制作有道词典——标题栏
|
小程序
【Axure教程】用中继器制作移动端图片上传效果
【Axure教程】用中继器制作移动端图片上传效果
【Axure教程】用中继器制作移动端图片上传效果
GLS-高度表制作
文章目录 制作高度计 目的 配置工作环境 Object的设计 创建背光板(Bezel) 创建电动/气动开关 创建气压设定旋钮 创建高度计指针 创建高度计的里程表 创建气压计表 创建电动/气动显示标识 创建仪表的阴影 编译测试 代码开发 添加测试属性 添加属性来处理Altitude和Barometer Initialize Calculate 添加效用函数的头文件. Object的回调
174 0
GLS-高度表制作