ios - UIkit Dynamics in swift -
trying convert objective c code swift , struggling achieve results.
animator = [[uidynamicanimator alloc] initwithreferenceview:self.view]; _gravity = [[uigravitybehavior alloc] initwithitems:@[square]]; at moment have got
animator.referenceview = self.view doesn't work though. can guide me in right direction. in advance
full code
let square = uiview()      square.frame = cgrectmake(100, 100, 100, 100)     square.backgroundcolor = uicolor.redcolor()    self.view.addsubview(square)      var animator = uidynamicanimator()     var gravity = uigravitybehavior()        animator.referenceview = self.view      animator.addbehavior(gravity) 
holex on it, key have store reference animator, here's working example:
class viewcontroller: uiviewcontroller {      var animator:uidynamicanimator?      override func viewdidload() {         super.viewdidload()          let square = uiview()          square.frame = cgrectmake(100, 100, 100, 100)         square.backgroundcolor = uicolor.redcolor()          self.view.addsubview(square)          self.animator = uidynamicanimator(referenceview:self.view)         var gravity = uigravitybehavior(items: [square])          animator!.addbehavior(gravity)      }  } 
Comments
Post a Comment