BAFluidView

https://github.com/antiguab/BAFluidView

This view and it's layer create a 2D fluid animation that can be used to simulate a filling effect.

这个view以及他的layer创建出了一个2D液体流动的动画,用来模拟水流注入的效果。

Requirements

  • Works on any iOS device

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

为了运行这个项目,你需要clone这个repo,运行pod install之后就可以运行了。

Getting Started

BAFluidView is available through CocoaPods. To install it, simply add the following line to your Podfile:

你可以使用CocoaPods来安装,用pod “BAFluidView”即可。

pod "BAFluidView"

Basic

To add a BAFluidView to your app, add the line:

添加以下代码就可以将效果添加到你的app中:

BAFluidView *view = [[BAFluidView alloc] initWithFrame:self.view.frame];
[view fillTo:@1.0];
view.fillColor = [UIColor colorWithHex:0x397ebe];
[view startAnimation];

This creates the following view:

Advanced Usage

Listed below are examples of several properties that you can control.

以下是一些你可以控制的属性:

Init

You can use initWithFrame:maxAmplitude:minAmplitude:amplitudeIncrement: to control how high/low you want the wave to go. The increment method helps control the variation between the peaks. If you're only concerned is where the fluid starts, initWithFrame:(CGRect)aRect startElevation:(NSNumber*)aStartElevation creates a fluid view with default values, but lets you choose the starting elevation. To control all init values, use the method (id)initWithFrame:(CGRect)aRect maxAmplitude:(int)aMaxAmplitude minAmplitude:(int)aMinAmplitude amplitudeIncrement:(int)aAmplitudeIncrement startElevation:(NSNumber*)aStartElevation which is a combination of the two above.

你可以使用initWithFrame:maxAmplitude:minAmplitude:amplitudeIncrement:来控制波浪可以达到多高或者多低。increment方法这是为了控制波峰的大小。如果你只是关心从什么地方开始动画,用这个方法initWithFrame:(CGRect)aRect startElevation:(NSNumber*)aStartElevation。你可以用方法(id)initWithFrame:(CGRect)aRect maxAmplitude:(int)aMaxAmplitude minAmplitude:(int)aMinAmplitude amplitudeIncrement:(int)aAmplitudeIncrement startElevation:(NSNumber*)aStartElevation来达到最大的控制。

Animate Only Once (End in old state)

If you only want the effect to fill only once (or any specific amount of times) you can edit the fillRepeatCount property:

如果你只想填充一回,进行以下设置:

BAFluidView *view = [[BAFluidView alloc] initWithFrame:self.view.frame maxAmplitude:40 minAmplitude:5 amplitudeIncrement:5];
view.fillRepeatCount = 1;
[view fillTo:@1.0];
view.fillColor = [UIColor colorWithHex:0x397ebe];
[view startAnimation];

Animate Only Once (End in new state)

You can also create the same effect as above, but stay in the filled state by editing the fillAutoReverse property:

如果你想填充一回,并停留在最终的停留状态中,进行以下设置:

BAFluidView *view = [[BAFluidView alloc] initWithFrame:self.view.frame maxAmplitude:40 minAmplitude:5 amplitudeIncrement:5];
view.fillColor = [UIColor colorWithHex:0x397ebe];
view.fillAutoReverse = NO;
view.fillRepeatCount = 1;
[view fillTo:@1.0];
[view startAnimation];

Fill to specific level

By default, the animation goes to the top of the view. If you don't want it to go the entire distance, you can use the fillTo: method by giving it a percentage of the distance you want it to travel:

默认情况下,动画会填充到顶部去并填充满,如果你并不想这样子,你可以用方法fillTo:填充到指定的百分比处:

BAFluidView *view = [[BAFluidView alloc] initWithFrame:self.view.frame];
[view fillTo:@0.5];
view.fillColor = [UIColor colorWithHex:0x397ebe];
[view startAnimation];

Fill Color

By editing the fillColor property, you can give the fluid any color:

你可以通过修改fillColor属性来修改填充的颜色:

BAFluidView *fluidView = [[BAFluidView alloc] initWithFrame:self.view.frame startElevation:@0.5];
fluidView.strokeColor = [UIColor whiteColor];
fluidView.fillColor = [UIColor colorWithHex:0x2e353d];
[fluidView keepStationary];
[fluidView startAnimation];

Stroke Color

Similiarly, you can alter the stroke property. With a clear fillColor you get a wave effect like below:

你也可以通过修改stroke属性来修改描边的颜色:

BAFluidView *fluidView = [[BAFluidView alloc] initWithFrame:self.view.frame startElevation:@0.5];
fluidView.fillColor = [UIColor clearColor];
fluidView.strokeColor = [UIColor whiteColor];
[fluidView keepStationary];
[fluidView startAnimation];

Use as a Layer

If you want to add the effect to another view, use it's layer!

如果你想使用他的layer,很简单,就用它的layer座位mask就行了!

BAFluidView *fluidView = [[BAFluidView alloc] initWithFrame:self.view.frame startElevation:@0.3];
fluidView.fillColor = [UIColor colorWithHex:0x397ebe];
[fluidView fillTo:@0.9];
[fluidView startAnimation]; UIImage *maskingImage = [UIImage imageNamed:@"icon"];
CALayer *maskingLayer = [CALayer layer];
maskingLayer.frame = CGRectMake(CGRectGetMidX(fluidView.frame) - maskingImage.size.width/2, 70, maskingImage.size.width, maskingImage.size.height);
[maskingLayer setContents:(id)[maskingImage CGImage]];
[fluidView.layer setMask:maskingLayer];

[翻译] BAFluidView的更多相关文章

  1. 《Django By Example》第五章 中文 翻译 (个人学习,渣翻)

    书籍出处:https://www.packtpub.com/web-development/django-example 原作者:Antonio Melé (译者@ucag注:大家好,我是新来的翻译, ...

  2. 《Django By Example》第四章 中文 翻译 (个人学习,渣翻)

    书籍出处:https://www.packtpub.com/web-development/django-example 原作者:Antonio Melé (译者注:祝大家新年快乐,这次带来<D ...

  3. [翻译]开发文档:android Bitmap的高效使用

    内容概述 本文内容来自开发文档"Traning > Displaying Bitmaps Efficiently",包括大尺寸Bitmap的高效加载,图片的异步加载和数据缓存 ...

  4. 【探索】机器指令翻译成 JavaScript

    前言 前些时候研究脚本混淆时,打算先学一些「程序流程」相关的概念.为了不因太枯燥而放弃,决定想一个有趣的案例,可以边探索边学. 于是想了一个话题:尝试将机器指令 1:1 翻译 成 JavaScript ...

  5. 《Django By Example》第三章 中文 翻译 (个人学习,渣翻)

    书籍出处:https://www.packtpub.com/web-development/django-example 原作者:Antonio Melé (译者注:第三章滚烫出炉,大家请不要吐槽文中 ...

  6. 《Django By Example》第二章 中文 翻译 (个人学习,渣翻)

    书籍出处:https://www.packtpub.com/web-development/django-example 原作者:Antonio Melé (译者注:翻译完第一章后,发现翻译第二章的速 ...

  7. 《Django By Example》第一章 中文 翻译 (个人学习,渣翻)

    书籍出处:https://www.packtpub.com/web-development/django-example 原作者:Antonio Melé (译者注:本人目前在杭州某家互联网公司工作, ...

  8. 【翻译】Awesome R资源大全中文版来了,全球最火的R工具包一网打尽,超过300+工具,还在等什么?

    0.前言 虽然很早就知道R被微软收购,也很早知道R在统计分析处理方面很强大,开始一直没有行动过...直到 直到12月初在微软技术大会,看到我软的工程师演示R的使用,我就震惊了,然后最近在网上到处了解和 ...

  9. ASP.NET MVC with Entity Framework and CSS一书翻译系列文章之第一章:创建基本的MVC Web站点

    在这一章中,我们将学习如何使用基架快速搭建和运行一个简单的Microsoft ASP.NET MVC Web站点.在我们马上投入学习和编码之前,我们首先了解一些有关ASP.NET MVC和Entity ...

随机推荐

  1. 面向UI编程框架:ui.js框架思路详细设计

    由于上一次的灵光一闪,萌生了对面向UI编程的思想实现.经过一段时间的考虑和设计,现在将思想和具体细节记录下来: 具体思路描述: 在UI.config文件中,配置所有参数,比如页面模板.所有组件.组件控 ...

  2. 4-nginx-反向代理到tomcat及负载均衡

    反向代理相比于正向代理, 比如使用搬瓦工时, 就是位于客户端的正想代理, 而反向代理则是服务器端的代理, 主要用于实现请求分发, 负载均衡等功能 正向代理推荐一个: 搬瓦工, 比较好用.. 反向代理主 ...

  3. [笔记] Python字典

    好记忆不如烂笔头: #__author:Mifen #date: 2018/11/28 #不可变类型:整型,字符串,浮点型(不等于小数,但包括小数),元组(只读,不可修改) #可变类型:列表,字典(键 ...

  4. .Net Actor 服务端开发框架,Newbe.Claptrap 项目周报 1 - 还没轮影,先用轮跑

    Newbe.Claptrap 项目周报 1,第一周代码写了一点.但主要还是考虑理论可行性. 第一次接触本框架的读者,可以先点击此处阅读本框架相关的基础理论和工作原理. 周报是啥? 成功的开源作品,离不 ...

  5. HTTP协议以及HTTP请求中8种请求方法

    HTTP协议以及HTTP请求中8种请求方法 什么是协议? 协议,是指通信的双方,在通信流程或内容格式上,共同遵守的标准. 什么是http协议? http协议,是互联网中最常见的网络通信标准. http ...

  6. Qt Model View 框架

    Model-View及Qt实现 Model-View-Controller架构最早出现在SmallTalk语言中,至今出现了很多变体. Model是负责维护数据(如管理数据库),View负责显示与用户 ...

  7. 使用jdk压缩war包

    首先安装jdk 压缩 ..../jdk/bin/jar -cvf file.war file 解压 ..../jdk/bin/jar -xvf file.war

  8. springcloud-Feign基础使用

    声明式REST客户端:Feign Feign是一个声明式的Web服务客户端.它使得Web服务客户端的写入更加方便.具有可插拔注解支持,包括Feign注解和JAX-RS注解. Spring Cloud增 ...

  9. Json.Net 反序列化成匿名对象

    反序列化一个object var str1 = "{id:1,name:'111',x:[1,2,3],y:{a:'ssss',b:'dddd'}"; var obj1 = Jso ...

  10. C#共享内存整理

    1.System.IO.MemoryMappedFiles 内存映射文件类 内存映射文件将文件的内容映射到应用程序的逻辑地址空间. 内存映射文件使程序员得以处理极大的文件(这是因为可以并发管理内存), ...