IOS Animation Animation-4-4:calayer Subclass: Careplicatorlayer

Source: Internet
Author: User

First of all: This is a series of articles, refer to other articles under this topic to help you understand this article.

The last piece introduced the Cashpelayer, and made two examples, if the creativity is stronger, those things can create the animation effect that you previously dared not imagine.

Today we're going to talk about careplication.
Careplication is a duplicate layer, you can copy the layers as required, first look at the Calayer based on the addition of those APIs

API Description
InstanceCount Number of repeating instance layer (hereinafter referred to as instance)
Instancedelay The time that the instance lasted
Instancetransform Instance animations
Instancecolor Instance Color
Instanceredoffset Red Offset
Instancegreenoffset Green Offset
Instanceblueoffset Blue Offset
Instancealphaoffset Transparency Offset

·
Today I take a chrysanthemum as an example, the effect is such a demo download

This can be used as the tableview of the drop-down refresh effect, of course, I am lazy, is a slider instead of the TableView drop offset.

His implementation is simple, so let's create a careplicatorlayer.

var replicatorLayer = CAReplicatorLayer()replicatorLayer.frame = someView.boundssomeView.layer.addSublayer(replicatorLayer)
    • Explain
      Same someview for the view created in storyboard
      Given size, and add it to the layer on Someview

In fact, this chrysanthemum is composed of a lot of duplicate rectangular layer. Then you need a rectangle layer.

10.0let midX = CGRectGetMidX(someView.bounds2instanceLayer.frame = CGRect(xy0.02.5)instanceLayer.backgroundColor = UIColor.whiteColor().CGColorreplicatorLayer.addSublayer(instanceLayer)
    • Explain
      The small rectangular layer created here is called Instancelayer
      Add it to Replicatorlayer

This is just to put a replicatorlayer on the view, and then add a rectangle layer, then you can start to set the properties of the Replicatorlayer

Set the color first

replicatorLayer.instanceColor = UIColor.grayColor().CGColor//        replicatorLayer.instanceRedOffset0.0//        replicatorLayer.instanceGreenOffset0.0//        replicatorLayer.instanceBlueOffset0.0//        replicatorLayer.instanceAlphaOffset0.0
    • Explain
      Color offset try to tune yourself to see what's changed.

Create a slider on storyboard, a way to generate a powerful person by dragging lines

@IBAction func Slider (sender:uislider) {Let count:int = Int (sender. Value* -) Replicatorlayer. InstanceCount= Count If sender. Value==1{Replicatorlayer. Instancedelay= Cftimeinterval (1.0/Double (count)) addanimation ()}else{if faderanimation! = Nil {Instancelaye R. Opacity=1.0Instancelayer. Removeanimationforkey("Fader")}} Replicatorlayer. Instancetransform= Catransform3dmakerotation (CGFloat (Float (M_PI *2.0) * Sender. Value/Float (count)),0.0,0.0,1.0)    }
    • Explain
      Setting Instanccount varies according to the value of the slider, int type
      Lasts for 1 seconds, the Cftimeinterval type, which represents the time required to generate count layer
      When the slider value is not 1.0, the animation is removed, and the opacity is set to 1
      Instancetransform, animating, the angle at which the 3D animation rotates around the z-axis

Add animations

func addAnimation() {        "opacity")        faderAnimation.fromValue1.0        faderAnimation.toValue0.0        faderAnimation.duration1        faderAnimation.repeatCount = Float(Int.max)        instanceLayer.opacity0.0        instanceLayer.addAnimation"fader")    }

Animation I do not explain, want to understand the animation please see the article under this topic

IOS Animation Animation-4-4:calayer Subclass: Careplicatorlayer

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.