ios - UIDynamics not working in Swift -


i'm attempting convert ray wenderlich's tutorial on uidynamics swift code, i'm stuck on first part.

http://www.raywenderlich.com/50197/uikit-dynamics-tutorial

here's i'm doing:

  1. created square uiview
  2. added uidynamicanimator main view
  3. added uigravitybehavior , initialized square
  4. added gravity behavior animator

it compiles , runs fine square doesn't move. can see i'm doing wrong?

https://github.com/oisinlavery/uidynamics-swift

you've created animator local variable go method, disappears method finished. needs instance variable on viewcontroller class stick around , work of animating square:

class viewcontroller: uiviewcontroller {     var animator: uidynamicanimator?      @ibaction func go(sender : uibutton) {         var square = uiview(frame: cgrectmake(100, 100, 100, 100))         square.backgroundcolor = uicolor.blackcolor()         self.view.addsubview(square)          self.animator = uidynamicanimator(referenceview: self.view)         var grav = uigravitybehavior(items:[square])          self.animator!.addbehavior(grav)     } } 

Comments

Popular posts from this blog

database - VFP Grid + SQL server 2008 - grid not showing correctly -

jquery - Set jPicker field to empty value -

.htaccess - htaccess convert request to clean url and add slash at the end of the url -