码迷,mamicode.com
首页 > 其他好文 > 详细

制作引导页[1]

时间:2014-08-11 20:31:02      阅读:203      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   color   io   for   2014   ar   

制作引导页[1]

bubuko.com,布布扣

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

效果:

bubuko.com,布布扣

源码:

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

几个需要注意的地方:

bubuko.com,布布扣

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

bubuko.com,布布扣

要确保添加在UIWindow上

bubuko.com,布布扣

最后记得从UIWindow上移除掉
bubuko.com,布布扣

很简单,对吧:)

 

制作引导页[1],布布扣,bubuko.com

制作引导页[1]

标签:style   blog   http   color   io   for   2014   ar   

原文地址:http://www.cnblogs.com/YouXianMing/p/3905310.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!