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.width  //屏幕宽度
#define L_SCREEN_HEIGHT [UIScreen mainScreen].bounds.size.height    //屏幕高

@implementation LaunchView

-(instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];

    if (self) {

    }
    return self;
}

//重写图片数组的setter方法
-(void)setImagesArray:(NSArray *)imagesArray
{
    _imagesArray = imagesArray;

    [self creatSubViews];
}

-(void)creatSubViews
{
    NSArray *imageArr = [NSArray arrayWithArray:_imagesArray];

    UIScrollView *mainScrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, L_SCREEN_WIDHT, L_SCREEN_HEIGHT)];
    mainScrollView.pagingEnabled = YES;
    mainScrollView.bounces = NO;
    mainScrollView.contentSize = CGSizeMake(L_SCREEN_WIDHT*imageArr.count, L_SCREEN_HEIGHT);
    mainScrollView.showsHorizontalScrollIndicator = NO;
    mainScrollView.delegate = self;
    [self addSubview:mainScrollView];

    //添加云彩图片
    UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 330, L_SCREEN_WIDHT, 170*L_SCREEN_WIDHT/1242.0)];
    imageView.image = [UIImage imageNamed:@"yun.png"];
    [self addSubview:imageView];

    for (int i=0; i<imageArr.count; i++) {
        UIView *rotateView = [[UIView alloc]initWithFrame:CGRectMake(L_SCREEN_WIDHT*i, 0, L_SCREEN_WIDHT, L_SCREEN_HEIGHT*2)];
        [rotateView setTag:L_Base_Tag+i];
        [mainScrollView addSubview:rotateView];
        if (i!=0) {
            rotateView.alpha = 0;
        }

        UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, L_SCREEN_WIDHT, L_SCREEN_HEIGHT)];
        imageView.image = [UIImage imageNamed:imageArr[i]];
        [rotateView addSubview:imageView];

        //最后页面添加按钮
        if (i == imageArr.count-1) {
            UIControl *control = [[UIControl alloc]initWithFrame:CGRectMake(0, L_SCREEN_HEIGHT-80, L_SCREEN_WIDHT, 50)];
            control.backgroundColor = [UIColor blackColor];
            [control addTarget:self action:@selector(ClickToRemove) forControlEvents:UIControlEventTouchUpInside];
            [rotateView addSubview:control];
        }
    }

    UIView *firstView = [mainScrollView viewWithTag:L_Base_Tag];
    [mainScrollView bringSubviewToFront:firstView];

}
-(void)scrollViewDidScroll:(UIScrollView *)scrollView{

    UIView * view1 = [scrollView viewWithTag:L_Base_Tag];
    UIView * view2 = [scrollView viewWithTag:L_Base_Tag+1];
    UIView * view3 = [scrollView viewWithTag:L_Base_Tag+2];
    UIView * view4 = [scrollView viewWithTag:L_Base_Tag+3];

    UIImageView * imageView1 = (UIImageView *)[scrollView viewWithTag:L_Base_Tag*2];
    UIImageView * imageView2 = (UIImageView *)[scrollView viewWithTag:L_Base_Tag*2+1];
    UIImageView * imageView3 = (UIImageView *)[scrollView viewWithTag:L_Base_Tag*2+2];
    UIImageView * imageView4 = (UIImageView *)[scrollView viewWithTag:L_Base_Tag*2+3];

    CGFloat xOffset = scrollView.contentOffset.x;

    //根据偏移量旋转
    CGFloat rotateAngle = -1 * 1.0/L_SCREEN_WIDHT * xOffset * M_PI_2 * L_Rotate_Rate;
    view1.layer.transform = CATransform3DMakeRotation(rotateAngle, 0, 0, 1);
    view2.layer.transform = CATransform3DMakeRotation(M_PI_2*1+rotateAngle, 0, 0, 1);
    view3.layer.transform = CATransform3DMakeRotation(M_PI_2*2+rotateAngle, 0, 0, 1);
    view4.layer.transform = CATransform3DMakeRotation(M_PI_2*3+rotateAngle, 0, 0, 1);

    //根据偏移量位移(保证中心点始终都在屏幕下方中间)
    view1.center = CGPointMake(0.5 * L_SCREEN_WIDHT+xOffset, L_SCREEN_HEIGHT);
    view2.center = CGPointMake(0.5 * L_SCREEN_WIDHT+xOffset, L_SCREEN_HEIGHT);
    view3.center = CGPointMake(0.5 * L_SCREEN_WIDHT+xOffset, L_SCREEN_HEIGHT);
    view4.center = CGPointMake(0.5 * L_SCREEN_WIDHT+xOffset, L_SCREEN_HEIGHT);

    //当前哪个视图放在最上面
    if (xOffset<L_SCREEN_WIDHT*0.5) {
        [scrollView bringSubviewToFront:view1];

    }else if (xOffset>=L_SCREEN_WIDHT*0.5 && xOffset < L_SCREEN_WIDHT*1.5){
        [scrollView bringSubviewToFront:view2];

    }else if (xOffset >=L_SCREEN_WIDHT*1.5 && xOffset < L_SCREEN_WIDHT*2.5){
        [scrollView bringSubviewToFront:view3];

    }else if (xOffset >=L_SCREEN_WIDHT*2.5)
    {
        [scrollView bringSubviewToFront:view4];

    }

    //调节其透明度
    CGFloat xoffset_More = xOffset*1.5>L_SCREEN_WIDHT?L_SCREEN_WIDHT:xOffset*1.5;
    if (xOffset < L_SCREEN_WIDHT) {
        view1.alpha = (L_SCREEN_WIDHT - xoffset_More)/L_SCREEN_WIDHT;
        imageView1.alpha = (L_SCREEN_WIDHT - xOffset)/L_SCREEN_WIDHT;;

    }
    if (xOffset <= L_SCREEN_WIDHT) {
        view2.alpha = xoffset_More / L_SCREEN_WIDHT;
        imageView2.alpha = xOffset / L_SCREEN_WIDHT;
    }
    if (xOffset >L_SCREEN_WIDHT && xOffset <= L_SCREEN_WIDHT*2) {
        view2.alpha = (L_SCREEN_WIDHT*2 - xOffset)/L_SCREEN_WIDHT;
        view3.alpha = (xOffset - L_SCREEN_WIDHT)/ L_SCREEN_WIDHT;

        imageView2.alpha = (L_SCREEN_WIDHT*2 - xOffset)/L_SCREEN_WIDHT;
        imageView3.alpha = (xOffset - L_SCREEN_WIDHT)/ L_SCREEN_WIDHT;
    }
    if (xOffset >L_SCREEN_WIDHT*2 ) {
        view3.alpha = (L_SCREEN_WIDHT*3 - xOffset)/L_SCREEN_WIDHT;
        view4.alpha = (xOffset - L_SCREEN_WIDHT*2)/ L_SCREEN_WIDHT;

        imageView3.alpha = (L_SCREEN_WIDHT*3 - xOffset)/L_SCREEN_WIDHT;
        imageView4.alpha = (xOffset - L_SCREEN_WIDHT*2)/ L_SCREEN_WIDHT;
    }

    //调节背景色
    if (xOffset <L_SCREEN_WIDHT && xOffset>0) {
        self.backgroundColor = [UIColor colorWithRed:(140-40.0/L_SCREEN_WIDHT*xOffset)/255.0 green:(255-25.0/L_SCREEN_WIDHT*xOffset)/255.0 blue:(255-100.0/L_SCREEN_WIDHT*xOffset)/255.0 alpha:1];

    }else if (xOffset>=L_SCREEN_WIDHT &&xOffset<L_SCREEN_WIDHT*2){

        self.backgroundColor = [UIColor colorWithRed:(100+30.0/L_SCREEN_WIDHT*(xOffset-L_SCREEN_WIDHT))/255.0 green:(230-40.0/L_SCREEN_WIDHT*(xOffset-L_SCREEN_WIDHT))/255.0 blue:(155-5.0/320*(xOffset-L_SCREEN_WIDHT))/255.0 alpha:1];

    }else if (xOffset>=L_SCREEN_WIDHT*2 &&xOffset<L_SCREEN_WIDHT*3){

        self.backgroundColor = [UIColor colorWithRed:(130-50.0/L_SCREEN_WIDHT*(xOffset-L_SCREEN_WIDHT*2))/255.0 green:(190-40.0/L_SCREEN_WIDHT*(xOffset-L_SCREEN_WIDHT*2))/255.0 blue:(150+50.0/L_SCREEN_WIDHT*(xOffset-L_SCREEN_WIDHT*2))/255.0 alpha:1];

    }else if (xOffset>=L_SCREEN_WIDHT*3 &&xOffset<L_SCREEN_WIDHT*4){

        self.backgroundColor = [UIColor colorWithRed:(80-10.0/L_SCREEN_WIDHT*(xOffset-L_SCREEN_WIDHT*3))/255.0 green:(150-25.0/L_SCREEN_WIDHT*(xOffset-L_SCREEN_WIDHT*3))/255.0 blue:(200-90.0/L_SCREEN_WIDHT*(xOffset-L_SCREEN_WIDHT*3))/255.0 alpha:1];
    }

}

#pragma 按钮的点击方法
-(void)ClickToRemove
{
    NSLog(@"进入主界面");
}

@end
时间: 2024-10-01 23:46:33

iOS引导页动画(封装好)的相关文章

html5跟随鼠标炫酷网站引导页动画特效

html5跟随鼠标炫酷网站引导页动画特效一款非常不错的引导页,文字效果渐变,鼠标跟随出绚丽的条纹.html5炫酷网站引导页,鼠标跟随出特效. 体验效果:http://hovertree.com/texiao/html5/ 效果图: 以下是源代码: 1 <!DOCTYPE html> 2 <html xmlns="http://www.w3.org/1999/xhtml"> 3 <head> 4 <meta http-equiv="Co

ios 引导页

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

墨迹天气引导页动画_Android源码

墨迹天气引导页动画,mojidemo为主项目.view.customviewpager为引用项目. 下载地址:http://www.devstore.cn/code/info/556.html 运行截图

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

核心动画的使用 - 引导页动画

1.引导页动画 1.1 ViewController.m @interface ViewController () <UIScrollViewDelegate> @property (weak, nonatomic) IBOutlet UIImageView *sunView; @property (weak, nonatomic) IBOutlet UIImageView *personView; @end @implementation ViewController - (void)vie

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引导页实现(一)

目前多数app在启动时会有引导页,今天给大家介绍一种比较直观,能够快速实现的引导页实现方法 最终效果就是有一个全屏的引导页,页面底部有UIPageControl 用来指示当前引导页为第几个页面 其中主要使用两个UI控件 UIPageControl *pageControl; //指示当前处于第几个引导页 UIScrollView *scrollView; //用于存放并显示引导页 首先,获取屏幕尺寸 //获取屏幕 宽度.高度 #define SCREEN_FRAME ([UIScreen mai

iOS彩票项目--第五天,新特性引导页的封装、返回按钮的自定义、导航控制器的滑动返回以及自定义滑动返回功能

一.上次实现了在AppDelegate中通过判断app版本决定是否进入新特性页面,今天将AppDelegate中的一坨进行了封装.将self.window的根控制器到底应该为新特性界面,还是主页面,封装到了导航工具类ChaosGuideTool 封装,先决定外面怎么用,然后实现方法.外部通过类方法调用  + (UIViewController *)chooseRootVC; 外部的APPDelegate 只是调用方法 之前的业务判断没有改变,只是将数据的存储进行了封装 二.返回按钮的自定义 <1

ios启动页动画

在AppDelegate.m文件中添加如下代码 //初始化UIImageView对象,其中mScreenWidth,mScreenHeight为定义的全局常量// mScreenWidth=self.view.frame.size.width  mScreenHeight=self.view.frame.size.height    UIImageView *splashView=[[UIImageView alloc] initWithFrame:CGRectMake(0, 0, mScree