不规则形状的Mask动画
不规则形状的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动画的更多相关文章
- 使用Win32 API创建不规则形状&带透明色的窗口
前一阵突然想起了9月份电面某公司实习时的二面题,大概就是说怎么用Win32 API实现一个透明的窗口,估计当时我的脑残答案肯定让面试官哭笑不得吧.所以本人决定好好研究下这个问题.经过一下午的摸索,基本 ...
- cocos2d-x 不规则形状按钮的点击判定
cocos2d-x 不规则形状按钮的点击判定 原理: 1.OpeGL ES提供了glReadPixels[^footnote]函数,来获取当前framebuffer上的像素数据 2.cocos2d-x ...
- 图片碎片化mask动画
图片碎片化mask动画 效果 源码 https://github.com/YouXianMing/Animations // // TransformFadeViewController.m // A ...
- Unity---动画系统学习(6)---Avatar Mask动画融合、Layers动画分层、IK反向动力学
1. 介绍 Avatar Mask(动画融合) 前面我们一直介绍的都是动画混合,一般用于解决边跑边转弯的问题.而动画融合一般用于解决例如边跑边挥手的问题. 简单说就是让跑步去控制腿的骨骼,挥手控制手的 ...
- html5 svg实现不规则形状图片触发事件
html5 svg实现不规则形状图片触发事件<pre><!DOCTYPE html><html lang="en"> <head> ...
- 不规则形状的Ifc构件顶点坐标获取
不规则形状的Ifc构件顶点坐标获取 今天有人问我,ifc构件的顶点坐标怎么获取,自己前年的时候写过类似的程序,但有点记不清了,最近一直用C++解析ifc,慎重起见,还是重新再写一次,java版本的获取 ...
- Unity 制作不规则形状button
在游戏开发中,我们有时需要制作不规则形状的按键. Unity3d中使用UGUI的Button控件只能实现规则的长方形按钮.而通过给Button的Image组件添加对应的贴图(sprite)我们可以实现 ...
- 动效解析工厂:Mask 动画
转载自:http://www.cocoachina.com/ios/20160214/15250.html 前言:很多动效都是多种动画的组合,有时候你可能只是需要其中某个动画,但面对庞杂的代码库或是教 ...
- pyqt 不规则形状窗口显示
#coding=utf- import sys from PyQt5.QtCore import Qt from PyQt5.QtWidgets import QWidget, QApplicatio ...
随机推荐
- APP性能测试开始之旅
你是不是也跟我一样在工作中存在着同样的问题,APP版本在上线后不断的会有市场人员或者用户反馈页面加载慢,进入页面loading很久(实际我们设置的加载超时是15秒,15秒内加载出内容则显示,15秒外未 ...
- CI框架中自带的加密解密如何应用
首先我们找到配置文件application/config/config.php ,找到如下代码: ? 1 $config['encryption_key'] = "YOUR KEY&quo ...
- 《MySQL技术内幕 InnoDB存储引擎 》学习笔记
第1章 MySQL体系结构和存储引擎 1.3 MySQL存储引擎 数据库和文件系统最大的区别在于:数据库是支持事务的 InnoDB存储引擎: MySQL5.5.8之后默认的存储引擎,主要面向OLTP ...
- 【AtCoder】ARC103
C - //// 为了防止一些多余的判断,我选择直接记录每个数的个数,然后枚举第一个数,找第一个数之外第二个数改变最少的情况下应该选什么 代码 #include <bits/stdc++.h&g ...
- 【noip模拟赛1】古韵之刺绣
描述 日暮堂前花蕊娇, 争拈小笔上床描, 绣成安向春园里, 引得黄莺下柳条. ——胡令能<咏绣障> 古时女子四德中有一项——女红.女红的精巧程度对于女子来说是十分重要的.韵哲君十分爱好女红 ...
- Java参数传值?or传引用?
O'Reilly's Javain a Nutshell by David Flanagan (see Resources) puts it best: "javamanipulates o ...
- odoo权限管理(二.记录管理)
规则保存在ir.rule模型表里,需要设置关联某个模型,关联很多组,访问权限控制和domian. 通过domain_force过滤出的一些记录来执行约束. 例子:经理只能删除状态为'cancel'的客 ...
- VB.NET中lambda的写法
lambda 或者叫匿名方法 '有返回值的匿名函数,func前面输入参数,最后一个输出参数 Dim func1 As Func(Of Integer, Integer) = Function(ByVa ...
- 网站截图工具EyeWitness
网站截图工具EyeWitness 在网页分析和取证中,往往需要大批量的网站截图.Kali Linux提供了一款网站批量截图工具EyeWitness.该工具不仅支持网址列表文件,还支持Nmap和Ne ...
- Codeforces Round #373 (Div. 2) A. Vitya in the Countryside 水题
A. Vitya in the Countryside 题目连接: http://codeforces.com/contest/719/problem/A Description Every summ ...