以下是通过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