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:
- created square uiview
- added uidynamicanimator main view
- added uigravitybehavior , initialized square
- added gravity behavior animator
it compiles , runs fine square doesn't move. can see i'm doing wrong?
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
Post a Comment