zoukankan      html  css  js  c++  java
  • 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

  • 相关阅读:
    智能推荐算法演变及学习笔记(三):CTR预估模型综述
    从中国农业银行“雅典娜杯”数据挖掘大赛看金融行业数据分析与建模方法
    智能推荐算法演变及学习笔记(二):基于图模型的智能推荐(含知识图谱/图神经网络)
    (设计模式专题3)模板方法模式
    (设计模式专题2)策略模式
    (设计模式专题1)为什么要使用设计模式?
    关于macOS上常用操作命令(持续更新)
    记录下关于RabbitMQ常用知识点(持续更新)
    EMERGENCY! EUREKA MAY BE INCORRECTLY CLAIMING INSTANCES ARE UP WHEN THEY'RE NOT. RENEWALS ARE LESSER THAN THRESHOLD AND HENCE THE INSTANCES ARE NOT BEING EXPIRED JUST TO BE SAFE.
    SpringCloud教程二:Ribbon(Finchley版)
  • 原文地址:https://www.cnblogs.com/DLS520/p/5093506.html
Copyright © 2011-2022 走看看