iOS Animations by Tutorials by 2018

iOS Animations by Tutorials by 2018

Author:2018
Language: eng
Format: epub
Publisher: Ray Wenderlich


MicMonitor: Monitors the input levels on your iPhone’s microphone and repeatedly calls a closure expression that you provide. This is where you have the chance to update the display.

Everything is ready for you to jump in and add some cool animations!

Setting up the replicator layer

Open ViewController.swift and add the following two properties:

let replicator = CAReplicatorLayer() let dot = CALayer()

dot will be a simple shape drawn using the CALayer basic properties such as background and border color. replicator will help you get multiple dot copies on screen.

Next, add the following constants you’ll need to create your animation:

let dotLength: CGFloat = 6.0 let dotOffset: CGFloat = 8.0

You’ll use the first constant as the width and height of the dot layer, while the second constant holds the offset between each dot replication.

To finish off the setup, you’ll have to add the replicator layer to the view controller’s view. Add the following to viewDidLoad():

replicator.frame = view.bounds view.layer.addSublayer(replicator)

Here, you make the replicator layer the same size as the view controller’s view and add it as a sub-layer. If you were to run the project at this point, nothing would appear to have changed; that’s because you didn’t add any visible content to replicate.

The next step is to dress up the dot layer and add it to replicator in order to display the replications. Append the following to viewDidLoad():

dot.frame = CGRect( x: replicator.frame.size.width - dotLength, y: replicator.position.y, width: dotLength, height: dotLength) dot.backgroundColor = UIColor.lightGray.cgColor dot.borderColor = UIColor(white: 1.0, alpha: 1.0).cgColor dot.borderWidth = 0.5 dot.cornerRadius = 1.5

You first position the dot layer towards the right edge of the replicator and therefore, the right edge of the screen. Then you set the layer’s background color and add a border. At this point the layer will look like the following:



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.