如下是經過UIScrollView實現的引導頁。app
AppDelegate.mide
// HandCircleatom
//spa
// Created by SR-APP-6 on 15/9/26.code
// Copyright (c) 2015年 SR-APP-6. All rights reserved.orm
//blog
#import "AppDelegate.h"rem
#import "ViewController.h"get
@interface AppDelegate ()animation
@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