你如何实现"时钟擦拭"在IOS /径向擦拭效果? [英] How do you achieve a "clock wipe"/ radial wipe effect in iOS?

查看:198
本文介绍了你如何实现"时钟擦拭"在IOS /径向擦拭效果?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有时你会看到一个时钟擦除动画使用。事情是这样的:

Sometimes you'll see a "clock wipe" animation in use. Something like this:

你将如何实现在iOS设备上的效果?

How would you achieve that effect in iOS?

(注:这个问题是一个枪手。我想分享的技术来创建一个时钟擦拭动画,但这样做没有共享教程的格式,所以我能来最接近的是问一个问题,然后提供了答案。这是故意的,并共享信息,因为我回答了自己其他人可能会发现有用的。请不要投下来我的帖子的一种尝试。)

(Note: This question is a "ringer." I wanted to share a technique for creating a clock wipe animation, but SO does not have a format for sharing tutorials, so the closest I can come is asking a question and then providing the answer. This is deliberate, and an attempt to share information that others might find useful. Please don't down vote my post because I answered it myself.)

推荐答案

答:

您需要创建CAShapeLayer并安装它作为您的视图层口罩。

You'd create CAShapeLayer and install it as a mask on your view's layer.

您会再安装一个弧形成跨越全360度,并有一个半径是这样的中心到角落的距离图像的一半的形状层。你想给它,这是同为半径的线宽。

You'd then install an arc into the shape layer that spanned a full 360 degrees, and had a radius that was half the center-to-corner distance of your image. You'd give it a line width that was the same as the radius.

最后,你会创建一个动画形状图层从0到1.0 strokeEnd属性CABasicAnimation。这将导致形状开始是空的(形象充分屏蔽)和动画面具作为饼片是变得越来越大,直到它在图像的全尺寸。

Finally, you'd create a CABasicAnimation that animates the strokeEnd property of the shape layer from 0 to 1.0. This would cause the shape to start out empty (image fully masked) and animate the mask as a "pie slice" that got bigger and bigger, until it was the full size of the image.

您可以下载在github上一个示例项目,我写了表演工作code这个动画,其他核心动画技术中:

You can download a sample project on github that I wrote that shows working code for this animation, among other Core Animation techniques:

CA动画演示上GitHub上

这篇关于你如何实现"时钟擦拭"在IOS /径向擦拭效果?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆