ios - Animate a UIView on a sine wave path -


enter image description here

how make uiview move along sine wave path? ideally, i'd able stop animation when uiview goes off screen , release it. see uiview->animatewithduration can animate on 1 property @ time, seems 2 exclusive things happening simultaneously: it's moving right , it's moving up/down.

you can simple cakeyframeanimation.

override func viewdidload() {     super.viewdidload()      let myview = uiview(frame: cgrect(x: 10, y: 100, width: 50, height: 50))     myview.backgroundcolor = uicolor.cyan     view.addsubview(myview)      let animation = cakeyframeanimation()     animation.keypath = "position"     animation.duration = 60  // 60 seconds     animation.isadditive = true // make animation position values later generate relative values.      // x = 0 x = 299, generate y values using sine.     animation.values = (0..<300).map({ (x: int) -> nsvalue in         let xpos = cgfloat(x)         let ypos = sin(xpos)          let point = cgpoint(x: xpos, y: ypos * 10)  // 10 give amplitude.         return nsvalue(cgpoint: point)     })     myview.layer.add(animation, forkey: "basic") } 

Comments

Popular posts from this blog

c# - How Configure Devart dotConnect for SQLite Code First? -

c++ - Clear the memory after returning a vector in a function -

erlang - Saving a digraph to mnesia is hindered because of its side-effects -