iOS引导页实现(一)

目前多数app在启动时会有引导页,今天给大家介绍一种比较直观,能够快速实现的引导页实现方法

最终效果就是有一个全屏的引导页,页面底部有UIPageControl 用来指示当前引导页为第几个页面

其中主要使用两个UI控件

    UIPageControl *pageControl; //指示当前处于第几个引导页
    UIScrollView *scrollView; //用于存放并显示引导页

首先,获取屏幕尺寸

//获取屏幕 宽度、高度
#define SCREEN_FRAME ([UIScreen mainScreen].bounds)
#define SCREEN_WIDTH ([UIScreen mainScreen].bounds.size.width)
#define SCREEN_HEIGHT ([UIScreen mainScreen].bounds.size.height)

初始化UI控件

    //初始化UI控件
    scrollView=[[UIScrollView alloc]initWithFrame:SCREEN_FRAME];
    scrollView.pagingEnabled=YES;
    [self.view addSubview:scrollView];

    pageControl=[[UIPageControl alloc]initWithFrame:CGRectMake(0, SCREEN_HEIGHT-50, SCREEN_WIDTH, 10)];
    pageControl.currentPageIndicatorTintColor=[UIColor colorWithRed:0.153 green:0.533 blue:0.796 alpha:1.0];
    [self.view addSubview:pageControl];
    pageControl.numberOfPages=3;

我们按照三个引导页来做,如果需要4个5个页面 可以修改pageControl.numberofPages;

创建三个UIImageView 并且初始化

<p style="margin-top: 0px; margin-bottom: 0px; font-size: 15px; font-family: Menlo;">    <span style="font-size: 11px; color: rgb(112, 61, 170);">UIImageView</span> *imageViewOne;</p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 15px; font-family: Menlo;">    <span style="font-size: 11px; color: rgb(112, 61, 170);">UIImageView</span> *imageViewTwo;</p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 15px; font-family: Menlo;">    <span style="font-size: 11px; color: rgb(112, 61, 170);">UIImageView</span> *imageViewThree;</p>

初始化第一个UIImageView

-(void)createViewOne{

    UIView *view = [[UIView alloc] initWithFrame:SCREEN_FRAME];

    imageViewOne = [[UIImageView alloc] initWithFrame:SCREEN_FRAME];
    imageViewOne.contentMode = UIViewContentModeScaleAspectFit;
    imageViewOne.image = [UIImage imageNamed:@"HelpFrist"];
    [view addSubview:imageViewOne];

    [scrollView addSubview:view];

}

其他两个类似方式实现

目前是效果出来了,但是引导页之间的相互切换还没有出来

下来需要给图片添加动作,当点击第一张图片的时候切换到第个引导页,点击第二个引导页切换到第三个引导页。

此处需要使用到给图片添加动作,可参考

http://blog.csdn.net/lwjok2007/article/details/46388935

还是一第一个图片为例,给上边的createViewOne方法再添加一段代码

-(void)createViewOne{

    UIView *view = [[UIView alloc] initWithFrame:SCREEN_FRAME];

    imageViewOne = [[UIImageView alloc] initWithFrame:SCREEN_FRAME];
    imageViewOne.contentMode = UIViewContentModeScaleAspectFit;
    imageViewOne.image = [UIImage imageNamed:@"HelpFrist"];
    [view addSubview:imageViewOne];

    UITapGestureRecognizer *singleTap1 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(buttonpress1:)];
    imageViewOne.userInteractionEnabled = YES;
    [imageViewOne addGestureRecognizer:singleTap1];

    [scrollView addSubview:view];

}

同时实现方法

buttonpress1

#pragma mark -- tap image
-(void)buttonpress1:(id)sender
{
    CGFloat pageWidth = CGRectGetWidth(self.view.bounds);
    CGPoint scrollPoint = CGPointMake(pageWidth, 0);
    [scrollView setContentOffset:scrollPoint animated:YES];

    pageControl.currentPage = 1;

}

其他两个仿照次方法即可

最终效果

源代码

#import "ViewController.h"

//获取屏幕 宽度、高度
#define SCREEN_FRAME ([UIScreen mainScreen].bounds)
#define SCREEN_WIDTH ([UIScreen mainScreen].bounds.size.width)
#define SCREEN_HEIGHT ([UIScreen mainScreen].bounds.size.height)

/**

 UIPageControl类提供一行点来指示当前显示的是多页面视图的哪一页。当然,由于UIPageControl类可视样式的点击不太好操作,所以最好是确保再添加了可选择的导航选项,以便让页面控件看起来更像一个指示器,而不是一个控件。当用户界面需要按页面进行显示时,使用UIPageControl控件将要显示的用户界面内容分页进行显示会使编程工作变得快捷。

 **/

@interface ViewController ()
{
    UIPageControl *pageControl; //指示当前处于第几个引导页
    UIScrollView *scrollView; //用于存放并显示引导页
    UIImageView *imageViewOne;
    UIImageView *imageViewTwo;
    UIImageView *imageViewThree;

}

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.

    //初始化UI控件
    scrollView=[[UIScrollView alloc]initWithFrame:SCREEN_FRAME];
    scrollView.pagingEnabled=YES;
    [self.view addSubview:scrollView];

    pageControl=[[UIPageControl alloc]initWithFrame:CGRectMake(0, SCREEN_HEIGHT-50, SCREEN_WIDTH, 10)];
    pageControl.currentPageIndicatorTintColor=[UIColor colorWithRed:0.153 green:0.533 blue:0.796 alpha:1.0];
    [self.view addSubview:pageControl];
    pageControl.numberOfPages=3;

    [self createViewOne];
    [self createViewTwo];
    [self createViewThree];

}

-(void)createViewOne{

    UIView *view = [[UIView alloc] initWithFrame:SCREEN_FRAME];

    imageViewOne = [[UIImageView alloc] initWithFrame:SCREEN_FRAME];
    imageViewOne.contentMode = UIViewContentModeScaleAspectFit;
    imageViewOne.image = [UIImage imageNamed:@"HelpFrist"];
    [view addSubview:imageViewOne];

    UITapGestureRecognizer *singleTap1 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(buttonpress1:)];
    imageViewOne.userInteractionEnabled = YES;
    [imageViewOne addGestureRecognizer:singleTap1];

    [scrollView addSubview:view];

}

-(void)createViewTwo{

    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(SCREEN_WIDTH, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
    imageViewTwo = [[UIImageView alloc] initWithFrame:SCREEN_FRAME];
    imageViewTwo.contentMode = UIViewContentModeScaleAspectFit;
    imageViewTwo.image = [UIImage imageNamed:@"HelpSecond"];
    [view addSubview:imageViewTwo];

    UITapGestureRecognizer *singleTap1 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(buttonpress2:)];
    imageViewTwo.userInteractionEnabled = YES;
    [imageViewTwo addGestureRecognizer:singleTap1];

    [scrollView addSubview:view];

}

-(void)createViewThree{

    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(SCREEN_WIDTH*2, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];

    imageViewThree = [[UIImageView alloc] initWithFrame:SCREEN_FRAME];
    imageViewThree.contentMode = UIViewContentModeScaleAspectFit;
    imageViewThree.image = [UIImage imageNamed:@"HelpThree"];
    [view addSubview:imageViewThree];

    UITapGestureRecognizer *singleTap1 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(buttonpress3:)];
    imageViewThree.userInteractionEnabled = YES;
    [imageViewThree addGestureRecognizer:singleTap1];

    [scrollView addSubview:view];
}

#pragma mark -- tap image
-(void)buttonpress1:(id)sender
{
    CGFloat pageWidth = CGRectGetWidth(self.view.bounds);
    CGPoint scrollPoint = CGPointMake(pageWidth, 0);
    [scrollView setContentOffset:scrollPoint animated:YES];

    pageControl.currentPage = 1;

}

-(void)buttonpress2:(id)sender
{
    CGFloat pageWidth = CGRectGetWidth(self.view.bounds);
    CGPoint scrollPoint = CGPointMake(pageWidth*2, 0);
    [scrollView setContentOffset:scrollPoint animated:YES];

    pageControl.currentPage = 2;

}

-(void)buttonpress3:(id)sender
{
    NSLog(@"引导页完成");

}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end

为方便共享源代码 交流学习

苹果开发群 :414319235  欢迎加入

时间: 2024-07-30 12:28:58

iOS引导页实现(一)的相关文章

ios 引导页

引导页 1 先在AppDelegate里做一个判断,如果程序是第一次运行也就是在本地没有运行过的记录 (可以通过NSUserDefaults来记录程序是否有运行过的痕迹) 2 判断如果程序是第一次运行就把AppDelegate的rootViewController等于引导页,引导页是一个viewController,里面设置一个UIScrollView把需要滚动的引导页贴在滚动视图上,在最后一张图片上贴上一个button,点击button可进入程序首页 ,在进入首页的时候需要push出一个UIN

iOS引导页

我这里是的引导页是viewController #import <UIKit/UIKit.h> 我这里是将图片都加到了一个bundle的文件里#define GET_IMAGE_FROM_BUNDLE_PATH(imageName,bundleName) [ResBundleUtils imageNamedFromImagesBundlePNG:imageName withSubPath:bundleName] //适配3.5寸屏和4寸品的图片名#define ADAPT_IMAGE_NAME

IOS引导页拨动4张图片最后一张停三秒进入主页

// //  ViewController.m //  LIBAOZHENG0826 // //  Created by 张艳锋 on 15/8/26. //  Copyright (c) 2015年 张艳锋. All rights reserved. // #import "ViewController.h" @interface ViewController () { BOOL isOut; } @end @implementation ViewController - (void

iOS引导页动画(封装好)

//直接上代码,在外面只要调用,传入图片数组即可. // Created by 刘志武 on 2016/12/3. // Copyright ? 2016年 zhiwuLiu. All rights reserved. // #import "LaunchView.h" #define L_Base_Tag 10000 #define L_Rotate_Rate 1 #define L_SCREEN_WIDHT [UIScreen mainScreen].bounds.size.wid

ios引导页 设定以及 图片尺寸

iphone的屏幕尺寸有着几种: iphone 4/4s: 3.5 寸 分辨率:640X960 高宽比 640/960 = 1.5 iphone 5/5c/5s:4 寸 分辨率:640X1136 高宽比 1136/640 = 1.775 iphone 6 4.7寸 分辨率:750X1334 高宽比1334/750 = 1.775 iphone 6s 5.5寸 分辨率:1242X2208 高宽比 2208/1242 = 1.778 各型号手机的高宽比:只有4/4s的 高宽比是1.5其他都近视1.7

iOS App引导页功能实现

一.写作原因 以前都没有想着来写点东西,今天遇到件事情让我决定每次还是要做记录.因为以前自己可以轻松的完成pod spec的配置,但是今天在做的时候还是忘了遇到了很多坑.pod spec配置遇到的坑不在这里写,后面会单独写一点,但是内容不会太多.一是方便别人,二是方便自己. 第一次来发帖,写的不对的地方,请大神指出.我一定好好的努力修改并向大家学习,但是还是不太喜欢一惯的喷子.就像大家说的经典一样`close your mouth show me your code`,英文不好如果错了,大家见谅

iOS - GitHub干货分享(APP引导页的高度集成 - DHGuidePageHUD - ②)

距上一篇博客"APP引导页的高度集成 - DHGuidePageHUD - ①"的发布有一段时间了, 后来又在SDK中补充了一些新的内容进去但是一直没来得及跟大家分享, 今天来跟大家分享一下, 还是一行代码搞定APP引导页, 废话不多说直接进入主题! 如果还没来得及看上一篇博客的话, 请大家点击这里进入: iOS - GitHub干货分享(APP引导页的高度集成 - DHGuidePageHUD - ①) ????; (一)老规矩先上GitHub连接,给大家节省时间(分享是一种美德,S

iOS App初次启动时的用户引导页制作实例分享

iOS App初次启动时的用户引导页制作实例分享 作者:老初 字体:[增加 减小] 类型:转载 时间:2016-03-09我要评论 这篇文章主要介绍了iOS App初次启动时的用户引导页制作实例分享,其中判断程序是否是第一次或版本更新以后第一次启动是一个关键点,需要的朋友可以参考下 应用程序APP一般都有引导页,引导页可以作为操作指南指导用户熟悉使用:也可以展现给用户,让用户了解APP的功能作用.引导页制作简单,一般只需要一组图片,再把图片组展现出来就可以了.展示图片组常用UIScrollVie

iOS帅气加载动画、通知视图、红包助手、引导页、导航栏、朋友圈、小游戏等效果源码

iOS精选源码 如丝般顺滑的微信朋友圈(点赞,评论,图文混排表情,... 动态菜单第三版本:动态项,自适应方向 仿appstore首页滚动效果 iOS 透明导航栏方案 TransparentNavigation 一键合成APP引导页,包含不同状态下的引导页操作方式,同时... 很帅的数据加载动画(可以用于数据列表加载的展现) 实现通知视图,零耦合JMNotifyView DDGBannerScrollView使用文档 微信7.0红包助手 ios CAAnimation动画和SceneKit小游戏