iOS app 如何添加引导页。

以下是通过UIScrollView实现的引导页。

 

  AppDelegate.m

//  HandCircle

//

//  Created by SR-APP-6 on 15/9/26.

//  Copyright (c) 2015年 SR-APP-6. All rights reserved.

//

 

#import "AppDelegate.h"

#import "ViewController.h"

@interface AppDelegate ()

 

@end

 

@implementation AppDelegate

 

 

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

    ViewController *viewController = [[ViewController alloc] init];

    self.window.rootViewController = viewController;

    [self.window makeKeyAndVisible];

    return YES;

}

end

封装的引导页RunPageController.h文件

#import <UIKit/UIKit.h>

@protocol RunPageControllerDelegate <NSObject>

-(void)OnButtonClick;

 

@end

@interface RunPageController : UIView

@property id<RunPageControllerDelegate>delegate;

@end

 引导页RunPageController.m文件

//
//  RunPageController.m
//  HandCircle
//
//  Created by SR-APP-6 on 15/9/26.
//  Copyright (c) 2015年 SR-APP-6. All rights reserved.
//

#import "RunPageController.h"
#import "Common.h"
@interface RunPageController()<UIScrollViewDelegate>
@property (nonatomic, strong)UIScrollView *runScrollView;
@property (nonatomic, strong)UIPageControl *pageController;
@property UIButton *onButton;


@end
@implementation RunPageController

- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        self.runScrollView = [[UIScrollView alloc] initWithFrame:self.frame];
        self.runScrollView.pagingEnabled = YES;
        self.runScrollView.contentSize = CGSizeMake(self.frame.size.width * 3, self.frame.size.height);
        [self addSubview:self.runScrollView];
        self.pageController = [[UIPageControl alloc] initWithFrame:CGRectMake(0, self.frame.size.height*.8, self.frame.size.width, 10)];
        self.pageController.currentPageIndicatorTintColor = [UIColor greenColor];
        self.pageController.numberOfPages = 3;
        [self addSubview:self.pageController];
        CGPoint scrollPoint = CGPointMake(0, 0);
        [self.runScrollView setContentOffset:scrollPoint animated:YES];
        //添加引导页
        [self creatOne];
        [self creatTwo];
        [self creatThree];
            }
    return self;
}
#pragma mark -- 点击进入
- (void)onButtonGO{
    [self.delegate OnButtonClick];
}
#pragma mark --UIScrollViewDelegate
- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
    CGFloat PageIndictor = self.runScrollView.contentOffset.x/MAINVIEWWIDTH;
    self.pageController.currentPage = roundf(PageIndictor);
}
#pragma mark -- 添加启动页
- (void)creatOne{
    UIImageView *imageView= [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"0启动页1"]];
    imageView.frame = CGRectMake(0, 0, MAINVIEWWIDTH, MAINVIEWHEIGHT);
    imageView.contentMode = UIViewContentModeScaleAspectFit;
    self.runScrollView.delegate = self;
    [self.runScrollView addSubview:imageView];
}
- (void)creatTwo{
    UIImageView *imageView= [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"0启动页2"]];
    imageView.frame = CGRectMake(MAINVIEWWIDTH, 0, MAINVIEWWIDTH, MAINVIEWHEIGHT);
    imageView.contentMode = UIViewContentModeScaleAspectFit;
    self.runScrollView.delegate = self;
    [self.runScrollView addSubview:imageView];
}

- (void)creatThree{
    UIImageView *imageView= [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"0启动页3"]];
    imageView.frame = CGRectMake(MAINVIEWWIDTH * 2, 0, MAINVIEWWIDTH, MAINVIEWHEIGHT);
    imageView.contentMode = UIViewContentModeScaleAspectFit;
    self.runScrollView.delegate = self;
    [self.runScrollView addSubview:imageView];
    self.onButton = [[UIButton alloc] initWithFrame:CGRectMake(MAINVIEWWIDTH/2 - 50, MAINVIEWHEIGHT * 0.8, 100, 50)];
    [self.onButton setTitle:@"立即进入" forState:UIControlStateNormal];
    [self.onButton addTarget:self action:@selector(onButtonGO) forControlEvents:UIControlEventTouchUpInside];
    self.onButton.backgroundColor = [UIColor greenColor];
    imageView.userInteractionEnabled = YES;
    [imageView addSubview:self.onButton];

}






@end

 控制器实现的代码。

//
//  ViewController.m
//  HandCircle
//
//  Created by SR-APP-6 on 15/9/26.
//  Copyright (c) 2015年 SR-APP-6. All rights reserved.
//

#import "ViewController.h"
#import "RunPageController.h"
@interface ViewController ()<RunPageControllerDelegate>
@property RunPageController *RunPageControllerView;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor clearColor];
    self.RunPageControllerView = [[RunPageController alloc] initWithFrame:self.view.frame];
    self.RunPageControllerView.delegate = self;
    [self.view addSubview:self.RunPageControllerView];
}
#pragma mark -- RunPageControllerDelegate
-(void)OnButtonClick{
    [UIView animateWithDuration:0.5 animations:^{
        self.RunPageControllerView.alpha = 0;
    } completion:^(BOOL finished) {
        [self.RunPageControllerView removeFromSuperview];
    }];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end

 

 

下面是源码连接地址:http://pan.baidu.com/s/1mh42HeC

转载于:https://www.cnblogs.com/DLS520/p/5093506.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值