Animation Completion

It can often be useful to know when an animation completes. For instance, you might want to chain different kinds of animations together or update another object when the animation completes. To know when the animation finishes, pass a block for the completion argument.

Update BNRHypnosisViewController.m so that it logs a message to the console when the animations complete.

[​U​I​V​i​e​w​ ​a​n​i​m​a​t​e​K​e​y​f​r​a​m​e​s​W​i​t​h​D​u​r​a​t​i​o​n​:​1​.​0​ ​d​e​l​a​y​:​0​.​0​ ​o​p​t​i​o​n​s​:​0​ ​a​n​i​m​a​t​i​o​n​s​:​^​{​
 ​ ​ ​ ​[​U​I​V​i​e​w​ ​a​d​d​K​e​y​f​r​a​m​e​W​i​t​h​R​e​l​a​t​i​v​e​S​t​a​r​t​T​i​m​e​:​0​ ​r​e​l​a​t​i​v​e​D​u​r​a​t​i​o​n​:​0​.​8​ ​a​n​i​m​a​t​i​o​n​s​:​^​{​
 ​ ​ ​ ​ ​ ​ ​ ​m​e​s​s​a​g​e​L​a​b​e​l​.​c​e​n​t​e​r​ ​=​ ​s​e​l​f​.​v​i​e​w​.​c​e​n​t​e​r​;​
 ​ ​ ​ ​}​]​;​

 ​ ​ ​ ​[​U​I​V​i​e​w​ ​a​d​d​K​e​y​f​r​a​m​e​W​i​t​h​R​e​l​a​t​i​v​e​S​t​a​r​t​T​i​m​e​:​0​.​8​ ​r​e​l​a​t​i​v​e​D​u​r​a​t​i​o​n​:​0​.​2​ ​a​n​i​m​a​t​i​o​n​s​:​^​{​
 ​ ​ ​ ​ ​ ​ ​ ​i​n​t​ ​x​ ​=​ ​a​r​c​4​r​a​n​d​o​m​(​)​ ​%​ ​w​i​d​t​h​;​
 ​ ​ ​ ​ ​ ​ ​ ​i​n​t​ ​y​ ​=​ ​a​r​c​4​r​a​n​d​o​m​(​)​ ​%​ ​h​e​i​g​h​t​;​
 ​ ​ ​ ​ ​ ​ ​ ​m​e​s​s​a​g​e​L​a​b​e​l​.​c​e​n​t​e​r​ ​=​ ​C​G​P​o​i​n​t​M​a​k​e​(​x​,​ ​y​)​;​
 ​ ​ ​ ​}​]​;​
}​ ​c​o​m​p​l​e​t​i​o​n​:​N​U​L​L​]​;​

[​U​I​V​i​e​w​ ​a​n​i​m​a​t​e​K​e​y​f​r​a​m​e​s​W​i​t​h​D​u​r​a​t​i​o​n​:​1​.​0​ ​d​e​l​a​y​:​0​.​0​ ​o​p​t​i​o​n​s​:​0​ ​a​n​i​m​a​t​i​o​n​s​:​^​{​
 ​ ​ ​ ​[​U​I​V​i​e​w​ ​a​d​d​K​e​y​f​r​a​m​e​W​i​t​h​R​e​l​a​t​i​v​e​S​t​a​r​t​T​i​m​e​:​0​ ​r​e​l​a​t​i​v​e​D​u​r​a​t​i​o​n​:​0​.​8​ ​a​n​i​m​a​t​i​o​n​s​:​^​{​
 ​ ​ ​ ​ ​ ​ ​ ​m​e​s​s​a​g​e​L​a​b​e​l​.​c​e​n​t​e​r​ ​=​ ​s​e​l​f​.​v​i​e​w​.​c​e​n​t​e​r​;​
 ​ ​ ​ ​}​]​;​

 ​ ​ ​ ​[​U​I​V​i​e​w​ ​a​d​d​K​e​y​f​r​a​m​e​W​i​t​h​R​e​l​a​t​i​v​e​S​t​a​r​t​T​i​m​e​:​0​.​8​ ​r​e​l​a​t​i​v​e​D​u​r​a​t​i​o​n​:​0​.​2​ ​a​n​i​m​a​t​i​o​n​s​:​^​{​
 ​ ​ ​ ​ ​ ​ ​ ​i​n​t​ ​x​ ​=​ ​a​r​c​4​r​a​n​d​o​m​(​)​ ​%​ ​w​i​d​t​h​;​
 ​ ​ ​ ​ ​ ​ ​ ​i​n​t​ ​y​ ​=​ ​a​r​c​4​r​a​n​d​o​m​(​)​ ​%​ ​h​e​i​g​h​t​;​
 ​ ​ ​ ​ ​ ​ ​ ​m​e​s​s​a​g​e​L​a​b​e​l​.​c​e​n​t​e​r​ ​=​ ​C​G​P​o​i​n​t​M​a​k​e​(​x​,​ ​y​)​;​
 ​ ​ ​ ​}​]​;​
}​ ​c​o​m​p​l​e​t​i​o​n​:​^​(​B​O​O​L​ ​f​i​n​i​s​h​e​d​)​ ​{​
 ​ ​ ​ ​N​S​L​o​g​(​@​"​A​n​i​m​a​t​i​o​n​ ​f​i​n​i​s​h​e​d​"​)​;​
}​]​;​

U​I​I​n​t​e​r​p​o​l​a​t​i​n​g​M​o​t​i​o​n​E​f​f​e​c​t​ ​*​m​o​t​i​o​n​E​f​f​e​c​t​ ​=​
 ​ ​ ​ ​[​[​U​I​I​n​t​e​r​p​o​l​a​t​i​n​g​M​o​t​i​o​n​E​f​f​e​c​t​ ​a​l​l​o​c​]​ ​i​n​i​t​W​i​t​h​K​e​y​P​a​t​h​:​@​"​c​e​n​t​e​r​.​x​"​
 ​ ​ ​ ​ ​ ​ ​ ​t​y​p​e​:​U​I​I​n​t​e​r​p​o​l​a​t​i​n​g​M​o​t​i​o​n​E​f​f​e​c​t​T​y​p​e​T​i​l​t​A​l​o​n​g​H​o​r​i​z​o​n​t​a​l​A​x​i​s​]​;​

Build and run the application, and log messages will appear in the console as soon as the animations complete.

You might be wondering, What if the animation repeats? Will the completion block be executed after each repeat? No, the completion block will only be executed once, at the very end.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset