不规则形状的Mask动画

效果

源码

https://github.com/YouXianMing/Animations

//
// MaskShapeViewController.m
// Animations
//
// Created by YouXianMing on 16/7/10.
// Copyright © 2016年 YouXianMing. All rights reserved.
// #import "MaskShapeViewController.h"
#import "AppleSystemService.h"
#import "JSAnimatedImagesView.h"
#import "CutOutClearView.h"
#import "UIView+SetRect.h"
#import "UIFont+Fonts.h"
#import "FBShimmeringView.h" typedef enum : NSUInteger { kUpJsView = ,
kDownJsView, } EMaskShapeViewControllerValue; @interface MaskShapeViewController () <JSAnimatedImagesViewDataSource> @property (nonatomic, strong) JSAnimatedImagesView *upJsView;
@property (nonatomic, strong) NSArray *upDataSource; @property (nonatomic, strong) JSAnimatedImagesView *downJsView;
@property (nonatomic, strong) NSArray *downDataSource; @end @implementation MaskShapeViewController - (void)setup { [super setup]; self.backgroundView.backgroundColor = [UIColor blackColor]; CGFloat gap = .f;
CGFloat offset = .f; {
CutOutClearView *areaView = [[CutOutClearView alloc] initWithFrame:CGRectMake(, , Width, self.contentView.height / .f + offset - gap)];
areaView.fillColor = [UIColor clearColor];
areaView.areaColor = [UIColor blackColor]; UIBezierPath *path = [UIBezierPath bezierPath];
[path moveToPoint:CGPointMake(gap, gap)];
[path addLineToPoint:CGPointMake(Width - gap, gap)];
[path addLineToPoint:CGPointMake(Width - gap, areaView.height)];
[path addLineToPoint:CGPointMake(gap, areaView.height - (offset - gap) * - gap)];
[path closePath];
areaView.paths = @[path]; self.upDataSource = @[[UIImage imageNamed:@""],
[UIImage imageNamed:@""],
[UIImage imageNamed:@""],
[UIImage imageNamed:@""],
[UIImage imageNamed:@""]]; self.upJsView = [[JSAnimatedImagesView alloc] initWithFrame:CGRectMake(, , Width, self.contentView.height / .f + offset - gap)];
self.upJsView.transitionDuration = .f;
self.upJsView.tag = kUpJsView;
self.upJsView.dataSource = self;
self.upJsView.layer.masksToBounds = YES;
self.upJsView.maskView = areaView;
[self.contentView addSubview:self.upJsView];
} {
CutOutClearView *areaView = [[CutOutClearView alloc] initWithFrame:CGRectMake(, , Width, self.contentView.height / .f + (offset - gap))];
areaView.fillColor = [UIColor clearColor];
areaView.areaColor = [UIColor blackColor]; UIBezierPath *path = [UIBezierPath bezierPath];
[path moveToPoint:CGPointMake(gap, )];
[path addLineToPoint:CGPointMake(gap, areaView.height - gap)];
[path addLineToPoint:CGPointMake(Width - gap, areaView.height - gap)];
[path addLineToPoint:CGPointMake(Width - gap, (offset - gap) * + gap)];
[path closePath];
areaView.paths = @[path]; self.downDataSource = @[[UIImage imageNamed:@"pic_1"],
[UIImage imageNamed:@"pic_2"],
[UIImage imageNamed:@"pic_3"],
[UIImage imageNamed:@"pic_4"]]; self.downJsView = [[JSAnimatedImagesView alloc] initWithFrame:CGRectMake(, , Width, self.contentView.height / .f + offset - gap)];
self.downJsView.transitionDuration = .f;
self.downJsView.tag = kDownJsView;
self.downJsView.dataSource = self;
self.downJsView.layer.masksToBounds = YES;
self.downJsView.maskView = areaView; self.downJsView.bottom = self.contentView.height;
[self.contentView addSubview:self.downJsView];
}
} #pragma mark - JSAnimatedImagesViewDataSource - (NSUInteger)animatedImagesNumberOfImages:(JSAnimatedImagesView *)animatedImagesView { NSUInteger count = ;
animatedImagesView.tag == kUpJsView ? (count = self.upDataSource.count) : (count = self.downDataSource.count); return count;
} - (UIImage *)animatedImagesView:(JSAnimatedImagesView *)animatedImagesView imageAtIndex:(NSUInteger)index { UIImage *image = nil;
animatedImagesView.tag == kUpJsView ? (image = self.upDataSource[index]) : (image = self.downDataSource[index]); return image;
} #pragma mark - Overwrite methods. - (void)buildTitleView { [super buildTitleView]; // Title label.
UILabel *headlinelabel = [UILabel new];
headlinelabel.font = [UIFont HeitiSCWithFontSize:.f];
headlinelabel.textAlignment = NSTextAlignmentCenter;
headlinelabel.textColor = [UIColor cyanColor];
headlinelabel.text = self.title;
[headlinelabel sizeToFit]; headlinelabel.center = self.titleView.middlePoint; FBShimmeringView *shimmeringView = [[FBShimmeringView alloc] initWithFrame:self.titleView.bounds];
shimmeringView.shimmering = YES;
shimmeringView.shimmeringBeginFadeDuration = 0.3;
shimmeringView.shimmeringOpacity = 0.1f;
shimmeringView.shimmeringAnimationOpacity = .f;
[self.titleView addSubview:shimmeringView]; shimmeringView.contentView = headlinelabel; // Line.
UIView *line = [[UIView alloc] initWithFrame:CGRectMake(, 63.5, self.view.width, 0.5f)];
line.backgroundColor = [[UIColor grayColor] colorWithAlphaComponent:0.25f];
[self.titleView addSubview:line];
[self.titleView addSubview:headlinelabel]; // Back button.
UIImage *image = [UIImage imageNamed:@"backIconVer2"];
UIButton *backButton = [[UIButton alloc] initWithFrame:CGRectMake(, , , )];
backButton.center = CGPointMake(, self.titleView.middleY);
[backButton setImage:image forState:UIControlStateNormal];
[backButton addTarget:self action:@selector(popSelf) forControlEvents:UIControlEventTouchUpInside];
[backButton.imageView setContentMode:UIViewContentModeCenter];
[self.titleView addSubview:backButton];
} - (void)popSelf { [self popViewControllerAnimated:YES];
} @end

细节

//
// CutOutClearView.h
// Animations
//
// Created by YouXianMing on 16/7/10.
// Copyright © 2016年 YouXianMing. All rights reserved.
// #import <UIKit/UIKit.h> @interface CutOutClearView : UIView /**
* The total fill color, you can used it as the view's background color.
*/
@property (nonatomic, strong) UIColor *fillColor; /**
* The paths area color.
*/
@property (nonatomic, strong) UIColor *areaColor; /**
* Path array.
*/
@property (nonatomic, strong) NSArray <UIBezierPath *> *paths; @end
//
// CutOutClearView.m
// Animations
//
// Created by YouXianMing on 16/7/10.
// Copyright © 2016年 YouXianMing. All rights reserved.
// #import "CutOutClearView.h" @implementation CutOutClearView - (instancetype)initWithFrame:(CGRect)frame { if (self = [super initWithFrame:frame]) { self.fillColor = [UIColor whiteColor];
self.backgroundColor = [UIColor clearColor];
self.opaque = NO;
} return self;
} - (void)drawRect:(CGRect)rect { [super drawRect:rect]; [self.fillColor setFill];
UIRectFill(rect); CGContextRef context = UIGraphicsGetCurrentContext(); if (self.areaColor && self.paths.count) { UIBezierPath *path = nil; for (int i = ; i < self.paths.count; i++) { i == ? path = self.paths[i] : [path appendPath:self.paths[i]];
} CGFloat red = ;
CGFloat green = ;
CGFloat blue = ;
CGFloat alpha = ;
[self.areaColor getRed:&red green:&green blue:&blue alpha:&alpha]; CGContextAddPath(context, path.CGPath);
CGContextSetRGBFillColor(context, red, green, blue, alpha);
CGContextFillPath(context); } else { for (UIBezierPath *path in self.paths) { CGContextAddPath(context, path.CGPath);
CGContextSetBlendMode(context, kCGBlendModeClear);
CGContextFillPath(context);
}
}
} @end

不规则形状的Mask动画的更多相关文章

  1. 使用Win32 API创建不规则形状&带透明色的窗口

    前一阵突然想起了9月份电面某公司实习时的二面题,大概就是说怎么用Win32 API实现一个透明的窗口,估计当时我的脑残答案肯定让面试官哭笑不得吧.所以本人决定好好研究下这个问题.经过一下午的摸索,基本 ...

  2. cocos2d-x 不规则形状按钮的点击判定

    cocos2d-x 不规则形状按钮的点击判定 原理: 1.OpeGL ES提供了glReadPixels[^footnote]函数,来获取当前framebuffer上的像素数据 2.cocos2d-x ...

  3. 图片碎片化mask动画

    图片碎片化mask动画 效果 源码 https://github.com/YouXianMing/Animations // // TransformFadeViewController.m // A ...

  4. Unity---动画系统学习(6)---Avatar Mask动画融合、Layers动画分层、IK反向动力学

    1. 介绍 Avatar Mask(动画融合) 前面我们一直介绍的都是动画混合,一般用于解决边跑边转弯的问题.而动画融合一般用于解决例如边跑边挥手的问题. 简单说就是让跑步去控制腿的骨骼,挥手控制手的 ...

  5. html5 svg实现不规则形状图片触发事件

    html5 svg实现不规则形状图片触发事件<pre><!DOCTYPE html><html lang="en"> <head> ...

  6. 不规则形状的Ifc构件顶点坐标获取

    不规则形状的Ifc构件顶点坐标获取 今天有人问我,ifc构件的顶点坐标怎么获取,自己前年的时候写过类似的程序,但有点记不清了,最近一直用C++解析ifc,慎重起见,还是重新再写一次,java版本的获取 ...

  7. Unity 制作不规则形状button

    在游戏开发中,我们有时需要制作不规则形状的按键. Unity3d中使用UGUI的Button控件只能实现规则的长方形按钮.而通过给Button的Image组件添加对应的贴图(sprite)我们可以实现 ...

  8. 动效解析工厂:Mask 动画

    转载自:http://www.cocoachina.com/ios/20160214/15250.html 前言:很多动效都是多种动画的组合,有时候你可能只是需要其中某个动画,但面对庞杂的代码库或是教 ...

  9. pyqt 不规则形状窗口显示

    #coding=utf- import sys from PyQt5.QtCore import Qt from PyQt5.QtWidgets import QWidget, QApplicatio ...

随机推荐

  1. Java @Override 注解

    @Override注解,不是关键字,但可以当关键字使用,可以选择添加这个注解,在你不留心重载而并非复写了该方法时,编译器就会产生一条错误:The method doh(Milhouse) of typ ...

  2. Java编程的逻辑 (35) - 泛型 (上) - 基本概念和原理

    本系列文章经补充和完善,已修订整理成书<Java编程的逻辑>,由机械工业出版社华章分社出版,于2018年1月上市热销,读者好评如潮!各大网店和书店有售,欢迎购买,京东自营链接:http:/ ...

  3. [转] React 最佳实践——那些 React 没告诉你但很重要的事

    前言:对很多 react 新手来说,网上能找到的资源大都是些简单的 tutorial ,它们能教会你如何使用 react ,但并不会告诉你怎么在实际项目中优雅的组织和编写 react 代码.用谷歌搜中 ...

  4. bzoj 1151: [CTSC2007]动物园zoo

    思路:因为每个人最多只能看到五个动物,我们考虑将其状压,f[ i ][ s ] 表示到了第 i 个位置, i, i + 1, i + 2, i + 3, i + 4这四个动物的状态为s, 此时的最大值 ...

  5. Linux常用包的安装

    下面列出的这些包都有很强大的功能,也是非常实用常用的工具 gcc yum -y install gcc GNU编译器套件(GNU Compiler Collection) gcc-c++ yum -y ...

  6. 让HTML5来为你定位(转)

    add by zhj: HTML5的地理定位返回的应该都是GPS坐标,即WGS-84坐标,参见Map Types - Google Maps JavaScript API v3 本文使用的是Chrom ...

  7. Spring框架学习——Spring的体系结构详解

    1.Spring简介 Spring是一个轻量级Java开发框架,最早有Rod Johnson创建,目的是为了解决企业级应用开发的业务逻辑层和其他各层的耦合问题.它是一个分层的JavaSE/JavaEE ...

  8. Linux/CentOS设置全局代理(http)

    说明:为什么说是http代理,其实这个还不能说是全称走代理,罪名写的区别就是ICMP协议这个设置就无效,只能说是90%的应用都可以使用这个设置来实现代理访问,只有个别不行,比如一些软件根本不走http ...

  9. Message Queue协议AMQP

    历史: Message Queue的需求由来已久,80年代最早在金融交易中,高盛等公司采用Teknekron公司的产品,当时的Message queuing软件叫做:the information b ...

  10. 【shell学习笔记】curl命令总结

    2014-12-16 20:34 文思海辉 =========== CURL命令总结 1. 下载 curl -o [文件名称] www.baidu.com 2. 显示 HTTP request头信息 ...