首页 > 代码库 > iOS引导页动画(封装好)
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
iOS引导页动画(封装好)
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。