In this video you'll learn how to make use of CAAnimation delegate methods.
This is a companion discussion topic for the original entry at https://www.raywenderlich.com/3270-intermediate-ios-animation/lessons/6
In this video you'll learn how to make use of CAAnimation delegate methods.
I can’t edit the text fields even though I’ve set the delegate for the text fields and removing the infoappear animation inside the textFieldDidBeginEditing function. I’ve also tried it in the textFieldShouldBeginEditing function and returning true.
I’m having a cloud animation problem… Here’s what happens - YouTube
notice the little glitch from the little cloud, just to the right of the login button.
here’s the relevant code:
func animateCloud(cloudLayer: CALayer) {
//animate clouds
let cloudSpeed = Double(randomSpeed.nextInt()) / Double(view.frame.size.width)
let duration = NSTimeInterval(view.frame.size.width - cloudLayer.frame.origin.x) * cloudSpeed
let cloudMove = CABasicAnimation(keyPath: "position.x")
cloudMove.duration = duration
cloudMove.fromValue = cloudLayer.frame.origin.x
cloudMove.toValue = view.frame.size.width + cloudLayer.frame.size.width
cloudMove.delegate = self
cloudMove.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionLinear)
cloudMove.setValue("cloud", forKey: "name")
cloudMove.setValue(cloudLayer, forKey: "layer")
cloudMove.fillMode = kCAFillModeBackwards // I stuck this line in after seeing the artifact, but it didn't matter.
cloudLayer.addAnimation(cloudMove, forKey: nil)
}
and in the extension:
} else if name == "cloud" {
layer.frame.origin.x = -layer.frame.size.width
delay(seconds: Double(self.randomSpeed.nextInt() / 30), completion: {[unowned self] in
self.animateCloud(layer)
})
oh and randomSpeed is defined by this:
let randomSpeed = GKRandomDistribution(lowestValue: 20, highestValue: 40)
by the way, i stuck in the [unowned self] because i have this fear of memory cycles… was I correct to do so?
I basically solved my own problem by starting all the clouds off screen by changing their constraints… that doesn’t really seem like a clean solution though…
Do you see a glitch like that in the provided project with the video? Maybe you can just compare your code with the code from the completed project to see if there’s any difference
alrighty… i downloaded the resources and ran the challenge finished version… and yep… it exhibits the same bug. a couple clouds flash in their original position for a fraction of a second a couple times several seconds into the animation.
so i did manage to fix that with starting the clouds off screen but i’m sure there’s a better way… .yes?
A quick note that will help anyone trying to do this for iOS 10.
“iOS 10 moves animationDidStart and animationDidStop to a formal CAAnimationDelegate protocol. Like beyowulf says, make the class conform to the delegate and remove the override tag from the method.”
(source: having trouble using UIViewControllerAnimatedTransitioning with swift 3 - Stack Overflow)
The short cloud flash is still there. It is in the provided project materials. Also, when I move the clouds off the screen, the animations sometimes flash when I click the textFields right after they disappear on the right, before showing on the left again. Hope this great course gets an update soon.
I just finished challenge and didn’t encounter any problems with cloud animation.
Big Thanks for the video course!