uiview - how to perform action when collision happens in swift? (i'm not using sprite kit) -


 var animator0: uidynamicanimator! var gravity0: uigravitybehavior! var collision0: uicollisionbehavior! 

after adding these made view fall when collision happens want action performed, tried writing if statement in viewdidappear function : if y coordinate of view @ exact point perform action didn't work either.

make sure viewcontroller class conforms protocol, uicollisionbehaviourdelegate

class viewcontroller: uiviewcontroller, uicollisionbehaviordelegate  

now,

  • make viewcontroller delegate of collision object

     collision0.collisiondelegate = self 
  • implement following method

    func collisionbehavior(behavior: uicollisionbehavior!, begancontactforitem item: uidynamicitem!, withboundaryidentifier identifier: nscopying!, atpoint p: cgpoint) {   print("collision detected- \(identifier)")  //perform action wanted here.   } 

Comments

Popular posts from this blog

qt - Using float or double for own QML classes -

Create Outlook appointment via C# .Net -

ios - Swift Array Resetting Itself -